【发布时间】:2021-12-31 16:50:13
【问题描述】:
我有一个 WinForms MP3 播放器桌面应用程序 (.NET Framework 4.7.2),它使用 ElementHost 来承载 MediaElement 控件,并有一个 DispatcherTimer 来控制播放(例如更新 Slider)。
一切正常,但是当我退出应用程序时,我得到了"System.Threading.Tasks.TaskCanceledException: 'A task was canceled.'" 异常(我只在调试器下运行时才注意到它)。
这只不过是一种麻烦,而且感觉大多无害,但我不喜欢我不理解的例外情况。调用堆栈不是超级有用:
> mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task task) Unknown
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task) Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Wait(System.TimeSpan timeout) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherOperation operation, System.Threading.CancellationToken cancellationToken, System.TimeSpan timeout) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Action callback, System.Windows.Threading.DispatcherPriority priority, System.Threading.CancellationToken cancellationToken, System.TimeSpan timeout) Unknown
WindowsBase.dll!MS.Internal.WeakEventTable.OnShutDown() Unknown
WindowsBase.dll!MS.Internal.WeakEventTable.WeakEventTableShutDownListener.OnShutDown(object target, object sender, System.EventArgs e) Unknown
WindowsBase.dll!MS.Internal.ShutDownListener.HandleShutDown(object sender, System.EventArgs e) Unknown
发生这种情况是因为 WPF 堆栈没有以某种方式正确处理吗?我确保我的 DispatchTimer 在 MainForm_FormClosing 中停止,但也许我还需要清理其他东西?
当然,烦人不是一个关键问题。
【问题讨论】:
-
也许添加许多 未处理的异常 处理程序之一。或者清除 Debug > Windows > Exception settings 中的所有 first chance 设置选项