Want to open MDI Child in a different thread
I have a MDI Child Form which contains a DataGridView that is updated continuously with a Timer. I don't want SQL operations that fire on Timer interval to conflict with other operations and therefore want to use a different thread for this MDI Child 开发者_如何学JAVAForm.
I want to know what to create a thread. I am opening this Form from the MDI Parent Form's Load event. Shall I create a thread at that time and put all the loading code of MDI child there or elsewhere?
You can not do any UI things on another thread. A process only get's one UI thread and all UI code should run on that thread (trying to do UI things on a different thread will result in an exception).
What you should do, is have the timer run on the UI thread and spin off to a background thread from there. As the data returns, be aware that you need to use a Dispatcher to sync your results to the UI thread.
精彩评论