0
Error:
System.Exception: 'The application called an interface that was marshalled for a Different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))'
I’m trying to get a BitmapImage
from a StorageItemThumbnail
, but I can’t even create it, whenever I try to create it BitmapImage bitmapImage = new BitmapImage();
get the above error independently if I use Dispatcher.Invoke
or not. It is the only line that gives the problem.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetThumbnailFile();
}
private async void GetThumbnailFile()
{
BitmapImage image = await ThumbnailPhoto(@"C:\...\");
}
private async Task<BitmapImage> ThumbnailPhoto(string FilePath)
{
StorageFile sf = await StorageFile.GetFileFromPathAsync(FilePath);
StorageItemThumbnail fileThumbnail = await sf.GetThumbnailAsync(ThumbnailMode.SingleItem, 250);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileThumbnail);
return bitmapImage;
}
}
Windows 10 API to use Storagefile: Calling Windows 10 Apis From a Desktop Application
Do not work: resolution1, resolution2, Dispatcher.Invoke
.
Bitmapimage used: using Windows.UI.Xaml.Media.Imaging;
.