Search code examples
uwpio

UWP app hang in the string FileIO.WriteBytesAsync


I use Win10 and code:

CacheFolder = await ApplicationData.Current.LocalCacheFolder.CreateFolderAsync(CACHEFOLDER, CreationCollisionOption.OpenIfExists);
StorageFile _file = await CacheFolder.CreateFileAsync(key, CreationCollisionOption.ReplaceExisting);
await FileIO.WriteBytesAsync(_file, data);

file creates and byte[] saved there but exactly on the last string app hang. What maybe a reason? Where to dig? What is interesting, it happens not every run but very often.


Solution

  • I wrap this method in

    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
    ...
    }
    

    It works.