locked
Cancel all running task in class RRS feed

  • Question

  • Hi,

       I have task cancel problem in my application(Data from Task A is overlapping with Task B). I want to cancel all running task in my current(Process) class.

    public class Process
    {
       public async void ProcessOP1()
       {
          //Await task operation
       }
       public async void ProcessOP2()
       {
          //Await task operation
       }
       public async void ProcessOP3()
       {
          //Await task operation
       }
    }

    procObj.ProcessOP1();
    procObj.ProcessOP2();
    procObj.ProcessOP3();

    Is there anyway to cancel all running task some thing like below..

    procObj.CancellAllTask();

    I know CancellationTokenSource class to cancel a task.. But for a class level how handle. Could anyone help for me fix my problem..?


     


    Dheeraj PK http://dheerajpk.wordpress.com/

    Wednesday, September 11, 2013 6:10 AM

Answers

  • You can create List<CancellationTokenSource> and in method CancelAllTask() stop all tasks in your list.
    • Proposed as answer by Dave SmitsMVP Wednesday, September 11, 2013 10:44 AM
    • Marked as answer by Anne Jing Monday, September 16, 2013 3:55 AM
    Wednesday, September 11, 2013 6:38 AM