open form in Thread

  • Thread starter Thread starter LiFo
  • Start date Start date
Hi,

You should interact with the UI only from the main thread, what you can do
is create a delegate and fire an event to be executed on the UI thread,
there you can open a new window with no problem.

You can inherit from EventArgs to add the object you need to pass to the
event.



Cheers,
 
Hi, LiFo

You can use Form.ShowDialog as usual on any thread. But you might have to
ensure dialog will be shown not behind some other window, which might happen
to be active at that moment.

If you want to show standard form, you might do this with Application.Run on
it. It will work Ok if there is no interaction with forms on other threads,
including UI. Otherwise, you'll have to resort to Invoke methods and
InvokeRequired checks.

You don't need to pass objects in constructors. Just add some set property
in the form, create it with new and set object to property.
If you want to pass object to thread - see MSDN
http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconCreatingThreads.asp

HTH
Alex
 
i have tryed to make an methode in MainForm that makes an form and shows it
and pass an delegate to the class that is supposed to show the form

but no diffrence when i call the delegate the form shows up and freezes
but if i use ShowDialog() it shows up fine
??

so i am going to try with an thread
 
Back
Top