R4D4
R4D4

Reputation: 1402

Creating a WinForm on the main thread using a backgroundworker

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?

Upvotes: 0

Views: 428

Answers (1)

Rich
Rich

Reputation: 3720

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

Upvotes: 1

Related Questions