title: how to cancel Task quicker
body: <p>I have a Windows Service which starts a task on start up</p>
  
  <p>This task which has a while loop and after performing one iteration it go to sleep for 5 minutes.</p>
  
  <p>When I stop service, the task is cancelled first and later some other operations gets performed</p>
  
  <p>if the task is in sleep, it get cancelled only when it wakes up , i want it to be cancelled even if it is sleeping and don't want to wait for waking it up.</p>
  
  <p>following is the code</p>
  
  <pre><code>Task controllerTask = Task.Factory.StartNew(() =&gt;
  {
      var interval = 300;
      while(true)
      {
          if (cancellationToken.IsCancellationRequested) 
              break;
          Thread.Sleep(interval * 1000);
          if (cancellationToken.IsCancellationRequested) 
              break;
          //SOME WORK HERE
      }
  }, cancellationToken);
  </code></pre>
  
  <p>Is there any way?</p>
  
  <p>EDIT:
  I am not able to use Task.Delay , I can't find it in System.Threading.Tasks.Task namespace , because I am using .Net Framework 4.0 not 4.5</p>
  
  <p>Is there any other better solution that works with 4.0.</p>