I've got a background worker and I'm trying to get it to create an instance of a form, but I don't want the background worker thread to own the object, but would like the main thread to own it. Where do I start with this?
Asked
Active
Viewed 427 times
0
-
This looks like a very strange (=wrong) design. Why should a Bgw create a Form? – H H Jun 11 '11 at 10:06
-
When my application loads I show a certain form, create a mutex and start a TCP listener on a background worker. If a second instance loads since it can't get the same mutex it tells the first instance through the TCP listener that the application tried to load again. I'm then wanting the background worker (which is no longer locking) to tell the main thread to show a certain form. – R4D4 Jun 11 '11 at 10:25
1 Answers
1
You can use the Invoke and BeginInvoke functions to get the code to execute on the GUI thread. You could get your other thread to raise an event, then handle it in your main form, then your main form could invoke that call back onto its own thread (using InvokeRequired then Invoke) to launch the new form.
If you're using a background worker you may be able to put the OnProgressChanged method to use to signal back to your application to do something.
Also, take a look at this excellent book

Rich
- 3,640
- 3
- 20
- 24