我们在WPF应用程序中遇到了一个非常奇怪的问题。
启动时,我们的应用程序会触发一些服务请求。然后当窗口被加载时,直到我们按下一个键之前,它都无响应,CPU使用率为0%。
看起来像是UI死锁,尽管不是真正的死锁-我们可以调整大小和移动窗口。当附加调试器时,我们可以看到主线程在Win32.UnsafeNativeMethods.GetMessageW上-它没有等待锁,正如您通常在此类问题中看到的那样。
如果我们按下一个键,它就会继续处理我们传递给Dispatcher.BeginInvoke的操作。
这在调试和发布版本上都发生,但只有在使用MSBuild工具构建时才会出现。如果我在我的PC上构建应用程序,包括VS2010和VS2012-都针对.NET 4.0-该问题永远不会发生。
有什么想法可以确定是什么阻止了Dispatcher在按下键之前执行操作吗?
此致。
P.S-请参见以下UI线程堆栈跟踪。
WindowsBase.dll!MS.Win32.UnsafeNativeMethods.GetMessageW(ref System.Windows.Interop.MSG msg,System.Runtime.InteropServices.HandleRef hWnd,int uMsgFilterMin,int uMsgFilterMax)+ 0x14字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.GetMessage(ref System.Windows.Interop.MSG msg,System.IntPtr hwnd,int minMessage,int maxMessage)+ 0x80字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)+ 0x75字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)+ 0x49字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.Run()+ 0x4b字节 PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)+ 0x17字节 PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)+ 0x6f字节 PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)+ 0x26字节 PresentationFramework.dll!System.Windows.Application.Run()+ 0x1b字节 MyApp.App.Main()第50行+ 0xa字节
启动时,我们的应用程序会触发一些服务请求。然后当窗口被加载时,直到我们按下一个键之前,它都无响应,CPU使用率为0%。
看起来像是UI死锁,尽管不是真正的死锁-我们可以调整大小和移动窗口。当附加调试器时,我们可以看到主线程在Win32.UnsafeNativeMethods.GetMessageW上-它没有等待锁,正如您通常在此类问题中看到的那样。
如果我们按下一个键,它就会继续处理我们传递给Dispatcher.BeginInvoke的操作。
这在调试和发布版本上都发生,但只有在使用MSBuild工具构建时才会出现。如果我在我的PC上构建应用程序,包括VS2010和VS2012-都针对.NET 4.0-该问题永远不会发生。
有什么想法可以确定是什么阻止了Dispatcher在按下键之前执行操作吗?
此致。
P.S-请参见以下UI线程堆栈跟踪。
WindowsBase.dll!MS.Win32.UnsafeNativeMethods.GetMessageW(ref System.Windows.Interop.MSG msg,System.Runtime.InteropServices.HandleRef hWnd,int uMsgFilterMin,int uMsgFilterMax)+ 0x14字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.GetMessage(ref System.Windows.Interop.MSG msg,System.IntPtr hwnd,int minMessage,int maxMessage)+ 0x80字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)+ 0x75字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)+ 0x49字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.Run()+ 0x4b字节 PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)+ 0x17字节 PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)+ 0x6f字节 PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)+ 0x26字节 PresentationFramework.dll!System.Windows.Application.Run()+ 0x1b字节 MyApp.App.Main()第50行+ 0xa字节