Question

I would like to cancel a task using a cancellation token as described here: http://msdn.microsoft.com/en-us/library/dd997396.aspx.

The only difference is that:

I would like to start a task when I browse to a specific controller/Action, and cancel the task(tokenSource.Cancel()) to be called when I LEAVE, browse away from that specific action (page) I'm currently on. How would i do it? Thanks

Was it helpful?

Solution

I figured it out.

I wrote a custom Attribute Filter that does this. Then in the code I have the following:

tokenSource = new CancellationTokenSource();
CancellationToken ct = tokenSource.Token;

var taskRepository = UnityContainerSetup.Container.Resolve<ITaskRepository>();
taskRepository.GetTasksStatusAsync(siteId, tasksItem, ct); // ct is my cancellation token that I set to true => to cancel
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top