While "worker" is executing piece of code, I'm closing the whole window and I want to dispose it on closing that window because it is finishing it's code otherwise.
Task worker = Task.Factory.StartNew(new Action(() =>
{
// some code here
}
Unfortunetly, when I call worker.Dispose() in Close() there is an Exception:
A task may only be disposed if it is in a completion state (RanToCompletion, Faulted or Canceled)
Any suggestions how I can dispose it while it is working?