Ok, I got this to work finally, and it is not like Clemens said.. :(
The problem seems to be ... (and I believe it is) that LoadImage doesn't start another thread until it calls wc.DownloadFileTaskAsync
. This is the only thing that runs in another thread, therefore... the call to WaitOne()
is completly silly, since mutex is claimed by UI thread ...
The way I got it to work is...
private async void LoadImage()
{
WebClient wc = new WebClient();
await Task.Run(() =>
{
m.WaitOne();
FileInfo fi = new FileInfo(filename);
if (fi.Exists == false)
{
wc.DownloadFile(url, filename);
wc.Dispose();
}
m.ReleaseMutex();
});
m.WaitOne();
flowerImage = new BitmapImage(new Uri("pack://siteOfOrigin:,,,/" + filename));
m.ReleaseMutex();
isLoaded = true;
OnPropertyChanged("FlowerImage");
}