I have a WinForms MP3 player desktop app (.NET Framework 4.7.2) that is using ElementHost to host a MediaElement control and has a DispatcherTimer to control playback (such as updating a Slider).
Everything works fine, but when I exit the app, I get the "System.Threading.Tasks.TaskCanceledException: 'A task was canceled.'" exception (I notice it only when running under the debugger).
It's nothing but a nuisance and feels mostly harmless, but I don't like exceptions that I don't understand. The callstack is not super useful:
> 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
Is this happening because the WPF stack does not get disposed properly somehow? I ensure my DispatchTimer is stopped in MainForm_FormClosing but perhaps there is something else I need to clean up?
Not a critical issue, of course, by annoying.