I have started a task on Start Task
button click and want to cancel that task > using Cancel Task
button. But I am not able to find & cancel running task.
public ActionResult StartTask()
{
var tokenSource = new CancellationTokenSource();
CancellationToken ct = tokenSource.Token;
Task.Factory.StartNew(() =>
{
// do some work...
}, tokenSource.Token);
return view();
}
public ActionResult CancelTask()
{
//Here i want to cancel above task.
return view();
}
Thanks in advance...