我在计算应用程序中发生的异常时遇到问题。
基本上,我正在托管一个wpf用户控件,该控件中有一个基础结构XamDataGrid
当我关闭应用程序时,我会得到一个类型为的异常的无限循环
线程"(0x24020)已退出,代码为0(0x0)。PresentationFramework.dll中首次出现"System.NullReferenceException"类型的异常PresentationFramework.dll中首次出现"System.NullReferenceException"类型的异常PresentationFramework.dll中首次出现类型为"System.NullReferenceException"的异常
等等…
如果我删除XAMDATAGRID,一切都很好。。。所以我猜这是电网的问题。。。
堆栈跟踪的一部分是:(我不确定这是否有帮助:)
-------------------------------------------------------------------------------------------PresentationFramework.dll!System.Windows.DeferredAppResourceReference.GetValue(System.Windows.BaseValueSourceInternal valueSource=继承)+0x4d字节
WindowsBase.dll!System.Windows.DependencyObject.GetEffectiveValue(System.Windows.EntryIndex EntryIndex={System.Windows.EentryIndex},System.Windows.DdependencyProperty dp={System.Windows.DependencyProperty},System.Windows.RequestFlags请求)+0xe6字节
WindowsBase.dll!System.Windows.DependencyObject.GetValueEntry(System.Windows.EntryIndex EntryIndex,System.Windows.DdependencyProperty dp={System.Windows.DDependencyProperty},System.Windows.PropertyMetadata元数据={System.Windows.FrameworkPropertyMetadata},System.Windows.RequestFlags requests=FullyResolved)+0x2fe字节
WindowsBase.dll!System.Windows.DependencyObject.GetValue(System.Windows.DdependencyProperty-dp)+0x48字节PresentationFramework.dll!MS.Internal.Text.TextProperties.InitCommon(System.Windows.DependencyObject目标={System.Windows.Controls.TextBlock})+0x6b字节PresentationFramework.dll!MS.Internal.Text.TextProperties.TextProperties(System.Windows.FrameworkElement target={System.Windows.Controls.TextBlock},bool isTypeographyDefaultValue=true)+0x42字节
PresentationFramework.dll!System.Windows.Controls.TextBlock.GetLineProperties()+0x37字节
PresentationFramework.dll!System.Windows.Controls.TextBlock.EnsureTextBlockCache()+0x2f字节PresentationFramework.dll!System.Windows.Controls.TextBlock.MeasureOverride(System.Windows.Size约束)+0x50字节
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size available Size)+0x1ee字节
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size available Size)+0x249字节
PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement元素,System.Windows.Size约束)+0xfe字节
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size约束)+0x18字节PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size available Size)+0x1ee字节
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size available Size)+0x249字节
PresentationFramework.dll!System.Windows.Controls.Control.MeasureOverride(System.Windows.Size约束)+0x10c字节PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size available Size)+0x1ee字节
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size available Size)+0x249字节
PresentationFramework.dll!System.Windows.Controls.StackPanel.MeasureOverride(System.Windows.Size约束)+0x187字节
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size available Size)+0x1ee字节
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size available Size)+0x249字节
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size约束)+0x1cf字节
对于如何解决这一问题的任何帮助,我们深表感谢!非常感谢。
发生此错误是因为当winforms应用程序关闭时,WPF调度程序线程尚未完成对事件消息的挂起队列的刷新。当它开始这样做时,应用程序对象已经被关闭并为null。要解决此问题,只需在关闭宿主窗口之前调用WPF消息循环上的shutdown即可。
Application.Current.Dispatcher.InvokeShutdown()