Having trawled t'internet for the answer to the following question, it seems that a lot of people have asked this over the years; here's the issue:-
I have my library working away just fine. I would now like to launch a UI so that someone can simulate some function or other, introduce errors, change variables etc...
So, I have my form
Form1 simUi;
and iv'e tried creating this in a method which is
[STAThread]
(seems to be t'internets favourite answer)
simUi = new Form1();
Now, here's the problem: If I use
simUi.ShowDialog();
The method never returns; at least until I close the form. Whereas, if I use
simUi.Show();
It returns but doesn't finish rendering the form and so is equally useless.
I want to be able to start the "ShowDialogue" in it's own thread but the compiler complains that the return type is incorrect.
So, how is best to do this ? Note that I have a number of controls on my form and so I don't just want to update a dialoge box. The plan is to use the properties in my form1.cs to access the responces on my UI and update any value's; I have a timer event to refresh.
Hopefully I am overlooking something that is obvious to all of you gurus'
Thanks Richard,
When I call the Show() method, the window appears but with no controls or buttons; just a blank grey box.
@Lukeer
guiThread = new System.Threading.Thread(new System.Threading.ThreadStart(simUi.ShowDialog));
guiThread.Start();
UPDATE:
Perhaps I need to elaborate a bit more:- My project is essentially an instrument class driver ; depending on which instrument is connected, it picks the correct driver to use and begins it’s work in it’s own thread. There wouldn’t ordinarily be any need for a UI but this dll is now being used by other people and teams. I had included a “simulation” feature to enable my development whilst not attached to any hardware but this was/is relatively simplistic. My internal “customers” are developing in the same way using my simulator but would like to invoke every error condition / state possible; this requires me to add a human interface. I know this is possible because I have seen similar done before.
So, if I could just find a way of running the ShowDialogue() in it’s won thread or getting the Show() to draw the controls, I’d have it licked…