我正在研究WPF应用程序,该应用程序有时会出现奇怪的问题,并且似乎在UI中挂起了。它不一致,它发生在不同的页面中,但它经常发生,这是一个很大的问题。我应该提到,它不是一个真正的悬挂,如下所述。如何解决WPF UI问题?
我的第一个想法是,一些按钮的动画是大多数页面上使用的问题,但是在删除它们之后仍会出现挂起,尽管看起来不太常见。发生挂起时,我试图打入调试器;但是从来没有任何代码可以查看。我的代码没有运行。我也注意到“挂起”并不完整。我有代码,可以让我拖动表单(它没有边框或标题),继续工作。我也有我的赢了关闭按钮,当我点击它时发挥作用。点击按钮看起来实际上可以在我的代码运行时正常工作,但UI不会更新以显示新页面。
我正在寻找任何建议,工具或技术来追踪这个奇怪的问题,所以如果你有任何想法,我将不胜感激。
编辑︰它再次发生,所以这次当我试图打入调试器,我选择“显示反汇编”。它带我到MS.Win32.UnsafeNativeMethods.GetMessageW。堆栈跟踪如下:
[Managed to Native Transition]
WindowsBase.dll中MS.Win32.UnsafeNativeMethods.GetMessageW(REF System.Windows.Interop.MSG味精,System.Runtime.InteropServices.HandleRef的HWND,INT uMsgFilterMin,INT uMsgFilterMax )+ 0x15 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.GetMessage(ref System.Windows.Interop.MSG msg,System.IntPtr hwnd,int minMessage,int maxMessage)+ 0x48 bytes WindowsBase.dll!System .Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame})+ 0x8b bytes WindowsBase.dll!System.Windows.Threading.Dispatcher。 PushFrame(System.Windows.Threading.DispatcherFrame frame)+ 0x49 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.Run()+ 0x4c bytes
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore )+ 0x1e bytes
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)+ 0x6f bytes PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)+ 0x26字节 PresentationFramework.dll!System.Windows.Application.Run()+ 0x19字节 WinterGreen.exe!WinterGreen.App.Main()+ 0x5e字节C# [原产于托管过渡]
[托管到NATIV e转换]
mscorlib.dll!System.AppDomain.nExecuteAssembly(System.Reflection.Assembly assembly,string [] args)+ 0x19 bytes mscorlib.dll!System.Runtime.Hosting.ManifestRunner.Run(bool checkAptModel)+ 0x6e字节 mscorlib.dll中!System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()+的0x84字节 mscorlib.dll中!System.Runtime.Hosting.ApplicationActivator.CreateInstance(System.ActivationContext activationContext,串[] activationCustomData)+ 0x65字节 mscorlib程序.dll!System.Runtime.Hosting.ApplicationActivator.CreateInstance(System.ActivationContext activationContext)+ 0xa bytes mscorlib.dll!System.Activator.CreateInstance(System.ActivationContext activationContext)+ 0x3e bytes
Microsoft.VisualStudio。 HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()+ 0x23 bytes
mscorlib.dll!System.Threading。ThreadHelper.ThreadStart_Context(object state)+ 0x66 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,object state)+ 0x6f bytes
mscorlib.dll! System.Threading.ThreadHelper.ThreadStart()+ 0x44字节
有些时候某些异步进程被执行;然而,这种行为可能随时发生,包括在启动后几乎没有任何运行时发生。 我会尝试删除无边界行为。 – palehorse 2008-09-19 18:23:40
仅需注意其他人将来阅读此内容:从不在调度程序中调用()或BeginInvoke()长时间运行的操作。你的用户界面似乎挂起...使用线程或BackgroundWorker或类似的东西。 – 2008-09-19 18:25:34
Bob是对的,如果你一次在UI线程上做的太多,UI将变得无法响应。你想在UI线程上做尽可能少的事情;任何大的操作都应该在后台线程上完成。 – 2008-09-19 18:28:39