如何解决WPF UI问题? [英] How do you troubleshoot WPF UI problems?

查看:137
本文介绍了如何解决WPF UI问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发WPF应用程序,有时会出现奇怪的问题,并在UI中显示为挂起。它是不一致的,它发生在不同的页面,但它经常发生,这是一个大问题。我应该提到这不是一个真正的挂起,如下所述。

I'm working on a WPF application that sometimes exhibits odd problems and appears to hang in the UI. It is inconsistent, it happens in different pages, but it happens often enough that it is a big problem. I should mention that it is not a true hang as described below.

我的第一个想法是,一些按钮的动画是这个问题,因为它们在大多数页面上使用,但是在删除它们之后仍然发生挂起,尽管看起来似乎不太频繁。挂起时我试图进入调试器;然而,从来没有任何代码可以查看。我的代码没有运行。我也注意到挂不完整。我有代码允许我拖动窗体(它没有边框或标题)继续工作。我也有我的关闭按钮,当我点击它的功能。点击按钮显示为实际工作,因为我的代码运行,但UI从来不会更新显示一个新的页面。

My first thought was that the animations of some buttons was the problem since they are used on most pages, but after removing them the hangs still occur, although seemingly a bit less often. I have tried to break into the debugger when the hang occurs; however there is never any code to view. No code of mine is running. I have also noticed that the "hang" is not complete. I have code that lets me drag the form around (it has no border or title) which continues to work. I also have my won close button which functions when I click it. Clicking on buttons appears to actually work as my code runs, but the UI simply never updates to show a new page.

我正在寻找任何建议,工具或技术跟踪这个奇怪的问题,所以如果你有任何想法,我将非常感激。

I'm looking for any advice, tools or techniques to track down this odd problem, so if you have any thoughts at all, I will greatly appreciate it.

编辑:刚刚发生了,所以这次我试过打破调试器我选择了显示反汇编。它带给我MS.Win32.UnsafeNativeMethods.GetMessageW。堆栈跟踪如下:

It just happened again, so this time when I tried to break into the debugger I chose to "show disassembly". It brings me to MS.Win32.UnsafeNativeMethods.GetMessageW. The stack trace follows:

[Managed to Native Transition]  




WindowsBase.dll!MS.Win32.UnsafeNativeMethods.GetMessageW(ref System.Windows.Interop.MSG 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字节

PresentationFramework.dll!System.Windows.Application.RunDispatcher(obje ct忽略)+ 0x1e个字节

PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window窗口)+ 0x6f字节
PresentationFramework.dll!System.Windows.Application.Run (System.Windows.Window窗口)+ 0x26字节
PresentationFramework.dll!System.Windows.Application.Run()+ 0x19 bytes
WinterGreen.exe!WinterGreen.App.Main()+ 0x5e bytes C#
[本机管理转换]

[管理到本地转换]

mscorlib.dll!System.AppDomain.nExecuteAssembly(System.Reflection.Assembly assembly,string [] args)+ 0x19 bytes
mscorlib.dll!System.Runtime.Hosting.ManifestRunner.Run(bool checkAptModel)+ 0x6e bytes
mscorlib.dll!System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()+ 0x84字节
mscorlib.dll!System.Runtime.Hosting.ApplicationActivator.CreateInstance(System.ActivationContext activationContext,string [] activationCustomData)+ 0x65 bytes
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(对象状态)+ 0x66字节

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 bytes

WindowsBase.dll!MS.Win32.UnsafeNativeMethods.GetMessageW(ref System.Windows.Interop.MSG 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 bytes PresentationFramework.dll!System.Windows.Application.Run() + 0x19 bytes WinterGreen.exe!WinterGreen.App.Main() + 0x5e bytes C# [Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.AppDomain.nExecuteAssembly(System.Reflection.Assembly assembly, string[] args) + 0x19 bytes mscorlib.dll!System.Runtime.Hosting.ManifestRunner.Run(bool checkAptModel) + 0x6e bytes mscorlib.dll!System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() + 0x84 bytes mscorlib.dll!System.Runtime.Hosting.ApplicationActivator.CreateInstance(System.ActivationContext activationContext, string[] activationCustomData) + 0x65 bytes 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 bytes


推荐答案

尝试删除无边界行为的窗口,看看是否有帮助。另外,你是否在BeginInvoke()中启动或调用())任何长时间运行的操作?

Try removing the borderless behavior of your window and see if that helps. Also, are you BeginInvoke()'ing or Invoke()'ing any long running operations?

另一件事要看:当你打破代码时,在线程以外的主线程。其中一个可能是阻止UI线程。

Another thing to look at: When you break into your code, try looking at threads other than your main thread. One of them may be blocking the UI thread.

这篇关于如何解决WPF UI问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆