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开发者_Python百科 all forms?
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.
If you do not do anything extra, all forms share the same UI thread (i suppose this is what you are referring to)
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...)
精彩评论