I have app where I'm using background worker to start some sequence. It needs to update GUI sometimes.
I have static class with references to some gui objects. In my logic I want to call method from this static class, with some parameters, there analyse it and update GUI. But I have "The calling thread cannot access this object because a different thread owns it." exception.
setting variable in first thread:
public static void SetCardHand(ref CardHand ch)
{
cardHand = ch;
}
Method called from background worker thread:
private static void SetCoveredCardsPlayer0(int cardsNumber)
{
if (cardsNumber < 1)
cardHand.imgCard1.Source = null;
else
cardHand.imgCard1.Source = (ImageSource)WindowManager.Instance.CardsGUI.CardsDictionary["T1"];
}
How to let this method change GUI?
edit
It's not a window class. Its something like presenter.
edit2
Its a card game. I'm starting it in background worker and I need to update Image source(representing card) after each Deal.