vasin
vasin

Reputation: 470

Thread for Windows form

When I'm creating a simple Windows form, is it starting in a new thread automatically? Or there is only one thread for all forms?

Upvotes: 0

Views: 612

Answers (3)

anchandra
anchandra

Reputation: 1099

If you do not do anything extra, all forms share the same UI thread (i suppose this is what you are referring to)

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564831

There is one thread for all forms.

In fact, Windows Forms (and most windowing technologies), require that all of your forms and controls be generated on a single thread. If you try to use a control from a different thread, it will cause a problem.

The UI thread in a Windows application actually spends most of its time idle. There is a message queue that is processed, and which causes the events you handle to be raised. If you want to access the UI from another thread, you have to invoke (using Control.Invoke) the method you want to run back onto the UI's thread, or you will receive exceptions.

Upvotes: 3

Dani
Dani

Reputation: 15079

No, It's only a message queue. forms (windows) looks like they are "multithreading" but this is message queue / message pump that processes messages. (so it's 1 thread...)

Upvotes: 0

Related Questions