I have this code in my WPF Application:
this.Closing += WindowOnClosing;
CancellationTokenSource cts = new CancellationTokenSource();
private void func()
{
Task task = new Task.Factory.Start(() =>
{
// long running code...
}), cts.Token);
await task;
}
private void WindowOnClosing(CancelEventArgs e)
{
cts.Cancel();
}
But whenI close the window, the task remains in running state.