문제

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

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top