首页 > 解决方案 > 几个小时的空闲时间后,用户控件重新启动(卸载+加载)

问题描述

这真是一件奇怪的事情。我有一个 WPF 应用程序,它加载一个仅包含一些图像的 UserControl。在幕后,此应用程序从各种 PerformanceCounter 收集数据,并每秒将数据写入磁盘。但是,如果我让应用程序在夜间运行,它将在大约 9 小时后卸载并重新加载用户控件(这不是固定的,而是大约在那个时间)。从 UserControl_Unloaded 事件中收集的堆栈跟踪中,我只看到有一个广播要卸载......

UNLOAD:    at PerformanceCollector.Controls.MenuControl.UserControl_Unloaded(Object sender, RoutedEventArgs e)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastUnloadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   

我完全不明白为什么会这样。CPU和内存坚如磐石。固定电脑没有在睡觉或任何东西。VS 异常设置中的所有内容都已勾选,因此不会发生错误。这里有两个奇怪的东西,为什么卸载,为什么又加载?但我将专注于理解为什么它会卸载并从那里开始。

有谁知道如何追求这个?我需要找出 BroadcastUnloadedEvent 的来源。WPF/.NET 中是否存在我缺少的“空闲”行为?一些我可以挂钩的事件或我可以使用的监控选项?在这里抓着稻草...

Windows 10、Visual Studio 2019、.NET 4.7.2。

标签: .netwpf

解决方案


推荐阅读