最近用worker thread用的比较频繁,找到了一篇讲workthread讲的非常好的blog,请戳这里
ps,那篇blog写的非常好,但是你能想象吗?!这是作者2001写的,15年了
再结合我最近碰到的问题说两句,以下是blog中提到的
Worker threads and the GUI II: Don't touch the GUI
That's right. A worker thread must not touch a GUI object. This means that you should not query the state of a control, add something to a list box, set the state of a control, etc.
Why?
Because you can get into a serious deadlock situation. A classic example was posted on one of the discussion boards, and it described something that had happened to me last year. The situation is this: you start a thread, and then decide to wait for the thread to complete. Meanwhile, the thread does something apparently innocuous, such as add something to a list box, or, in the example that was posted, calls FindWindow. In both cases, the process came to a screeching halt, as all threads deadlocked.
Let's analyze these two situations in some detail, so you get a sense of what happened.
In my case, the list box sent a notification, via SendMessage, to its parent. This means the message went to its parent thread. But the parent thread was blocked, waiting for the thread to complete. But the thread couldn't complet