接下来的问题是,WPF如何通知这个worker thread什么时候应该Render,这个thread跟main thread是如何通信的。要回答这个问题,我的做法是:
1. 选择一个非常简单的WPF程序,观察该程序idle状态时候每个thread的状态
2. 在Render thread上设定断点,当Render thread触发的时候,再次检查各个thread的状态。
于是我做了一个只有简单button的WPF程序,开始观察:
Idle 状态:
0:000> !clrstack
OS Thread Id: 0x145c (0)
ESP EIP
0012f354 7c8285ec [ComPlusMethodFrameGeneric: 0012f354] MS.Win32.UnsafeNativeMethods+ITfMessagePump.GetMessageW(System.Windows.Interop.MSG ByRef, Int32, Int32, Int32, Boolean ByRef)
0012f374 56d61937 System.Windows.Threading.Dispatcher.GetMessage(System.Windows.Interop.MSG ByRef, IntPtr, Int32, Int32)
0012f3c0 56d617e3 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
0012f410 56d616c7 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
0012f42c 56d6162d System.Windows.Threading.Dispatcher.Run()
0012f438 5533dce0 System.Windows.Application.RunInternal(System.Windows.Window)
0012f464 5533db15 System.Windows.Application.Run(System.Windows.Window)
0012f474 5533d766 System.Windows.Application.Run()
0012f47c 00f000ad WpfApplication1.App.Main()
0012f69c 79e7c74b [GCFrame: 0012f69c]
6 Id: 1874.103c S