title: What is the use of passing CancellationToken to Task Class constructor?
body: <p>Here is a sample code that creates a new task that simulates a long running process. There is nothing much on the task as such and purely focuses on the cancelling features. I am using cancellation token to cancel the task and the code works fine for me.</p>
  
  <pre><code>CancellationTokenSource CTS = new CancellationTokenSource();
  
  Task&lt;Boolean&gt; PTask = new Task&lt;Boolean&gt;(() =&gt; 
  {
     while (true)
     {
         if (!CTS.Token.IsCancellationRequested)
         {
            Thread.Sleep(5000);
         }
         else { Console.WriteLine("Thread Cancelled");break; }
     }
     return true;
  
  }, CTS.Token, TaskCreationOptions.None);
  
  PTask.Start();
  Console.WriteLine("Hit Enter to cancel the Secondary thread you have started");
  Console.ReadLine();
  CTS.Cancel();
  System.Console.WriteLine(PTask.Result);
  </code></pre>
  
  <p>But one thing that I could not understand is the token parameter (<code>CTS.Token</code>) that is being passed on to the <code>Task</code> constructor. What is the actual use of passing the parameter, when I can actually cancel the task even without passing token to the constructor.</p>
  
  <p>Down below is a slightly modified version that works without the token parameter.</p>
  
  <pre><code>CancellationTokenSource CTS = new CancellationTokenSource();
  Task&lt;Boolean&gt; PTask = new Task&lt;Boolean&gt;(() =&gt; 
  {
     while (true)
     {
         if (!CTS.Token.IsCancellationRequested)
         {
             Thread.Sleep(5000);
         }
         else
         {
             Console.WriteLine("Thread Cancelled");
             break;
         }
  };
  </code></pre>