I am running this code in a seperate thread on my C# Winforms app (the name of my form is MainForm):
DisplayDownload form2 = new DisplayDownload();
form2.TopMost = true;
form2.Show();
But when the thread is launched, the form never opens. If I move the code onto the main thread of my app, it opens fine, but if I launch it as it’s own thread, the form never opens.
I tried using the accepted answer from this post: Calling a windows form from another thread (.Net) but I get this error:
Cannot convert anonymous method to type ‘System.Delegate’ because it is not a delegate type
Here is the code I am trying to utilize:
MainForm.Invoke(delegate {
DisplayDownload form2 = new DisplayDownload();
form2.TopMost = true;
form2.Show();
});
Can someone please tell me what I am doing wrong and how to get it to work?
Add
new MethodInvoker(delegate(), So: