Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I realize the GUI is meant to be kept working all on the same thread. But, in this project I'd really like it if a new permanent form would show after another thread tells it to do so - and then that non-GUI thread expires.

 

The easy way around this would be to actually have a Hidden form up constantly in the program, and invoke the Visible property on it when it's needed. But is this a good and common practice?

 

So far, all I can do is create a form that disappears when the thread that created it expires, which makes sense because the form must not be attached properly to the GUI thread. I do use Invoke to Show the form, but that wont make a difference because It's not actually Invoking the GUI thread, but it's invoking the thread it was created on.. the non-GUI thread.

Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
  • Leaders
Posted

I think that, in general, what is considered proper is to create helper methods on a form that perform whatever UI operations you need to do from a secondary thread. You can call the Invoke method on said form (which should have been created under the GUI thread) to execute the code on the main thread.

 

This would include creating new forms. If you want to create a new form from a second thread, you should have that second thread invoke code on the main thread to do so. For instance, the app's main form can have a method to create a form and return a reference to it. The secondary thread invokes this method via the main form's Invoke method. Now suppose this secondary thread also needs to update the newly created form. The newly created form should expose methods that can be invoked from the secondary thread using the newly created form's Invoke method.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...