title: How can I cancel a Task without LOOP
body: <p>Hi I've been reading alot on the forum but I'm not able to find the answer to my problem...</p>
  
  <p>Here's my function that I want to cancel when a boolean turn to TRUE:</p>
  
  <pre><code>Task&lt;PortalODataContext&gt; task = Task.Factory.StartNew(() =&gt;
          {
              var context = connection.ConnectToPortal();
              connection.ListTemplateLib = this.ShellModel.ConnectionManager.GetTemplateLibrarys(connection);
              connection.ListTemplateGrp = this.ShellModel.ConnectionManager.GetTemplateGroups(connection, connection.TemplateLibraryId);
              connection.ListTemplates = this.ShellModel.ConnectionManager.GetTemplates(connection, connection.TemplateGroupId);
              return context;
         }, token);
  </code></pre>
  
  <p>How can I verify if the token got a cancel request without a LOOP ?</p>
  
  <p>Something like that :</p>
  
  <pre><code>if (token.IsCancellationRequested)
  {
      Console.WriteLine("Cancelled before long running task started");
      return;
  }
  
  for (int i = 0; i &lt;= 100; i++)
  {
      //My operation
  
      if (token.IsCancellationRequested)
      {
          Console.WriteLine("Cancelled");
          break;
      }
  }
  </code></pre>
  
  <p>But I dont have an operation that require a Loop so I dont know how to do that ...</p>