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:
.AsTask().Configure(false)
I particularly want to understand...
await StorageFile.GetFileFromPathAsync(path)
wait until the file is available before calling GetThumbnailAsync()User contributions licensed under CC BY-SA 3.0