Create forms with a thread?

  • Thread starter Thread starter Tomer
  • Start date Start date
T

Tomer

Hi,
I've a lot of form and I've tried running a thread that will create all
those form in the background, and insert them into a hashtable, when the
main application wants to go to a form it'll check the hashtable, and if the
form is there, activate it.

But for some reason this desn't work very well, the application gets stuck
when running a function inside the form, before the show method is called
(something like onShow method)

Tomer.
 
Tomer,

I don't think this approach is going to work, since Windows wants all access
to controls and forms to happen on the same thread that they were created
on - usually the main thread. You could just create each form once as it is
needed and save it for later reactivation though.
 
The reply has not changed from 3 weeks ago when I answered a very similar
question for you.
http://groups-beta.google.com/group...framework/browse_frm/thread/987bb1e0553e2170/

All Controls (including Forms) can only be touched (have any
methods/properties called) from the thread that created them. Conventional
wisdom and best practises suggest that the thread that does that is the main
(Application.Run) application thread.

When in need to touch controls from other threads use Control.Invoke

Cheers
Daniel
 
Right, just thought that this case in which I don't do the Show() it would
have worked.

You see I'm using CreateInstance for the form and it takes much more time
then the regular way, but I have no choise here.

Thanks, again.

Tomer.
 
Tomer,

I understand. Unfotunately I don't have any other suggestion. If you are
doing a lot of data manipulation or something like that when you instantiate
or load forms, you might be able to offload that to a different thread, but
I bet you've already thought of everything you can do along those lines.

How long are the delays you are seeing on instantiating your forms?
 
Back
Top