Could someone please explain to me the purpose or reasons for using Dispatcher.Invoke?
I am getting the error: *The calling thread cannot access this object because a different thread owns it. * and a quick Google search suggested that was due to not using Dispatcher.Invoke (they also said it was a common problem with newbies). This problem only started happening after I added the Task.Delay method, so it's obviously something to do with that?
The code that I am getting the error on is below:
if(ImageList.SelectedIndex < (c-1))
{
Task.Delay(1000).ContinueWith(_ =>
{
Background.Source = new BitmapImage(new Uri(Convert.ToString(AllImages[App.inx + 1])));
App.image1 = Convert.ToString(AllImages[App.inx]);
App.image2 = Convert.ToString(AllImages[App.inx + 1]);
}
);
}