Multiple GetThumbnailAsync calls gives error 0x8000000A

0

I'm trying to embrace async/await, so in my C# WPF app I have installed the Microsoft.Windows.SDK.Contracts nuget package to use StorageFile.GetFileFromPathAsync().

It works well for one thumbnail at a time...

StorageItemThumbnail thumb = await FetchThumbnailAsync(@"C:\Temp\z00.zip") 

public async Task<StorageItemThumbnail> FetchThumbnailAsync(string path)
{
    StorageFile storageFile = await StorageFile.GetFileFromPathAsync(path);
    StorageItemThumbnail thumbnail = await storageFile.GetThumbnailAsync(ThumbnailMode.SingleItem, 64);
    return thumbnail;
}

But if I try and call a few at once...

Task<StorageItemThumbnail> task1 = FetchThumbnailAsync(@"C:\Temp\z01.zip");
Task<StorageItemThumbnail> task2 = FetchThumbnailAsync(@"C:\Temp\z02.zip");
Task<StorageItemThumbnail> task3 = FetchThumbnailAsync(@"C:\Temp\z03.zip");

StorageItemThumbnail thumb1 = await task1;
StorageItemThumbnail thumb2 = await task2;
StorageItemThumbnail thumb3 = await task3;

Only one will succeed. The others will get this error from the GetThumbnailAsync() call...

Error for path 'C:\Temp\z01.zip': The data necessary to complete this operation is not yet available. (0x8000000A)
Error for path 'C:\Temp\z03.zip': The data necessary to complete this operation is not yet available. (0x8000000A)

Weirdly, it works reliably for all subsequent tasks if I let winrt "warm-up" by waiting until task1 is complete before running the rest at once...

StorageItemThumbnail thumb1 = await FetchThumbnailAsync(@"C:\Temp\z01.zip");

Task<StorageItemThumbnail> task2 = FetchThumbnailAsync(@"C:\Temp\z02.zip");
Task<StorageItemThumbnail> task3 = FetchThumbnailAsync(@"C:\Temp\z03.zip");

StorageItemThumbnail thumb2 = await task2;
StorageItemThumbnail thumb3 = await task3;

The issue occurs for .zip, .msi & .exe files, but not .png or .jpg files which always seem to work independent of the others erroring or not (so getting a thumbnail for an image does not "warm" things up for subsequent .zip calls).

Other notable but unsuccessful tests performed:

  • Calling GetFileFromPathAsync & GetThumbnailAsync with .AsTask().Configure(false)
  • Implementing FetchThumbnailAsync() as static.
  • Implementing FetchThumbnailAsync() in another class, so each call had it's own instance.
  • Using a new thread (from the pool) for each FetchThumbnailAsync() call.
  • The problem first occurred using NotifyTask<> from Stephen Cleary's Mvvm.Async library

I particularly want to understand...

  • how to make await StorageFile.GetFileFromPathAsync(path) wait until the file is available before calling GetThumbnailAsync()
  • why it works after "warm-up".
c#
wpf
async-await
windows-runtime
asked on Stack Overflow Jun 29, 2020 by moon

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0