I have searched quite a bit looking for how to invoke a control within a if statement for awhile now and haven't been able to find anything on this. I'm sure I'm missing something but if someone could show me how to do this that would be great. Here is a short piece of my code to give you an idea of where my problem is.
if(cardPanelOpponent.GetChildAtPoint(new Point(i, x)) == null)
{
OpponentCard.Location = new Point(i, x);
cardPanelOpponent.Invoke(new Action(() => cardPanelOpponent.Controls.Add(OpponentCard))
break; }
This line is taking place in a Async environment so I am getting a cross thread exception. How can I run this if statement while on a different thread then the UI.