i'm learning c# and wpf. i tried to load a img from net and bind it to a Image,but failed.
it says "The calling thread cannot access this object because a different thread owns it"
but i already used "Img1.Dispatcher.Invoke()",why it casue this exception again?
private void Window_ContentRendered(object sender, EventArgs e)
{
Img1.Dispatcher.Invoke(async () =>
{
Img1.Source = await DownloadImg("http address");
});
}
private Task<ImageSource> DownloadImg(string url)
{
return Task.Run(() =>
{
ImageSource source = new BitmapImage(new Uri(url));
return source;
});
}