here is part of my code:
public void refreshShowCase()
{
for (int i = 0; i < 12; ++i)
{
bitmapImage[i] = new BitmapImage(new Uri(posterURLCollection[i]));
image[i] = new Image { Source = bitmapImage[i] }; //Error occurs here****
}
}
when I run this I get this error: The calling thread must be STA, because many UI components require this.
So I add my code inside Disapther.Invoke
this.Dispatcher.Invoke((Action)delegate
{
BitmapImage[] bitmapImage = new BitmapImage[14];
Image[] image = new Image[14];
//Do a loop for defining Bitmaps sources
for (int i = 0; i < 12; ++i)
{
bitmapImage[i] = new BitmapImage(new Uri(posterURLCollection[i]));
image[i] = new Image { Source = bitmapImage[i] };
}
}
Now I have this error: 'Dispatcher' doesn't exist in the current context!
How should I solve this? Please help.
Update1: mentioned code is inside void of a class which I have created!