繁体   English   中英

WPF应用程序崩溃

[英]WPF application crash

我正在使用带有TabControl(3个带有textBlocks,标签和dataGrids的选项卡)的WPF应用程序。 应用程序使用后台线程自动刷新这些选项卡上的数据。 一切正常,除了以下事实:如果在后台进程之一触发时切换选项卡,它将引发“对象引用未设置为对象实例”错误并导致应用程序崩溃。 我设置了DispatcherUnhandledException来处理UI线程上任何未处理的异常。 堆栈跟踪除了说明错误来自TabControl以及可能与所选选项卡关联的对象这一事实外,没有提供太多数据。 我的问题是:WPF TabControl的固有问题是否可能导致此行为? 如前所述,我已经设置了我所知道的尽可能多的错误处理方法,但是收到的只是“对象引用...”错误。

堆栈跟踪:

System.Windows.Controls.ItemContainerGenerator.Generator.ctor(ItemContainerGenerator工厂,GeneratorPosition位置,GeneratorDirection方向,布尔值atStart。 System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.StartAt(GeneratorPosition位置,GeneratorDirection方向,Boolean allowStartAtRealizedItem)位于Microsoft.Windows.Controls的System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(大小约束)。 C:\\ dd \\ WPF_1 \\ src \\ wpf \\ src \\ ControlsPack \\ WPFToolkit \\ DataGrid \\ Microsoft \\ Windows \\ Controls \\ Primitives \\ DataGridRowsPresenter.cs:System.Windows.FrameworkElement上的第118行中的Primitives.DataGridRowsPresenter.MeasureOverride(大小约束)。 System.Windows.UIElement.Measure(Size av上的MeasureCore(Size availableSize) ailableSize)在System.Windows.Context.Manager.UpdateLayout()在System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)在System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()在System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()在System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)在System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate回调,对象args,布尔isSingleParameter)在System.Windows.Media.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)在系统Windows系统中的.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调,对象参数,布尔值isSingleParameter,委托catchHandler)在系统处.Windows.Threading.Dispatcher.WrappedInvoke(委托回调,对象参数,布尔值isSingleParameter,委托catchHandler)在系统处。 System.Windows.Threading.DispatcherOperation.InvokeInSecurityCon上的Windows.Threading.DispatcherOperation.InvokeImpl() System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuararededCleanup(TryCode代码,CleanupCode backoutCode,对象userData)在System.Threading.ExecutionContext.RunInternal(ExecutionContext执行上下文,ContextCallback)在System.Threading.ExecutionContext.runTryCode(对象userData)处的文本(对象状态)在System.Windows.Threading.DispatcherOperation.Invoke()在System.Windows.Threading.Dispatcher。 Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,布尔值和已处理)位于MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,IntPtr lParam,IntPtr Win32.HwndSubclass.DispatcherCallbackOperation(Object o)在System.Windows.Thread.ExceptionWrapper.InternalRealCall(委托回调,对象args,布尔isSingleParameter)在System.Windo ws.Threading.ExceptionWrapper.TryCatchWhen(Object source,Delegate callback,Object args,Boolean isSingleParameter,Delegate catchHandler)在System.Windows.Thread.Dispatcher.WrappedInvoke(Delegate callback,Object args,Boolean isSingleParameter,Delegate catchHandler)在System.Windows MS.Win32.HwndSubclass.SubclassWndProc.System.Windows.Thread.Dispatcher.Invoke(DispatcherPriority优先级,Delegate方法,对象arg)的.Threading.Dispatcher.InvokeImpl(DispatcherPriority优先级,TimeSpan超时,Delegate方法,对象args,布尔isSingleParameter) (位于MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&msg)位于System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)位于System.Windows.Threading.Dispatcher.PushFrame(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam) Sy的System.Windows.Application.RunInternal(Window窗口)的System.Windows.Application.RunDispatcher(Object ignore)的System.Windows.Threading.Dispatcher.Run()的DispatcherFrame框架) 在C:\\ Users \\ jfeltis \\ Documents \\ Expression \\ Blend 3 \\ Projects \\ salesforceConnect \\ salesforceConnect \\中的salesforceConnect.App.Main()处的System.Windows.Application.Run()处的stem.Windows.Application.Run(窗口窗口) obj \\ Debug \\ App.g.cs:第0行

这一切对我来说都是胡言乱语。 比我聪明的人可以看看一下,希望能给我一些指导吗? 谢谢。

尝试在您的SelectionChanged事件处理程序中放置一个断点,并在应用程序启动后立即单击其他选项卡。 您是否在任何选项卡中都有UserControl? 如果是这样,还可以在Loaded事件中放置一个断点。 至少当您达到断点时,后台线程将暂停,并且您可能能够看到哪个对象为空。

我使用的另一种蛮力方法是注释掉整个代码块,运行并测试,并逐步逐行取消注释,直到其中断为止。 然后,您至少知道一个潜在的崩溃位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM