Prerequisite Knowledge: 应用程序的Window hang住的主要原因是,它的UI线程正忙于某些事情而没有机会去处理message loop。
相信用过Vista的同志都会注意到,Windows Vista中当一个应用程序的Window hang住了,这个Window就会被灰化,并且Window的Title多了"Not Responding"前缀。但神奇的是,这个Window还是可以被Move, Resize, 和Close的。既然UI线程无暇顾及message loop,为什么它还能处理Move,Resize,和Close等Windows Message呢?
这关键是因为Windows Vista使用了一个叫ghost window的东西替换了原来的Window。您看到的那个灰化的Window已不是原来应用程序的Window了。这篇KB把ghost window的原理解释得很清楚:
http://support.microsoft.com/kb/934228
今天,我在无意中阅读到,原来Windows XP也有ghost window:
http://msdn.microsoft.com/en-us/library/ms644927.aspx
Microsoft Windows XP: If a top-level window stops responding to messages for more than several seconds, the system considers the window to be not responding. In this case, the system hides the window and replaces it with a ghost window that has the same Z order, location, size, and visual attributes. This allows the user to move it, resize it, or even close the application. However, these are the only actions available because the application is actually not responding. When in the debugger mode, the system does not generate a ghost window.
改天找台XP的系统测测看。