title: How to make a method cancelable without it becoming ugly?
body: <p>I am currently in the process of retrofitting our long-running methods to be cancelable. I am planning on using System.Threading.Tasks.CancellationToken to implement that.</p>
  
  <p>Our methods generally perform a few long-running steps (sending commands to and then waiting for hardware mostly), e.g.</p>
  
  <pre><code>void Run()
  {
      Step1();
      Step2();    
      Step3();
  }
  </code></pre>
  
  <p>My first (maybe stupid) thought on cancellation would transform this into</p>
  
  <pre><code>bool Run(CancellationToken cancellationToken)
  {
      Step1(cancellationToken);
  
      if (cancellationToken.IsCancellationRequested)
          return false;
  
      Step2(cancellationToken);
  
      if (cancellationToken.IsCancellationRequested)
          return false;    
  
      Step3(cancellationToken);
  
      if (cancellationToken.IsCancellationRequested)
          return false;
  
      return true;
  }
  </code></pre>
  
  <p>which frankly looks horrible. This "pattern" would continue inside the single steps, too (and they are necessarily rather longish already). This would make Thread.Abort() look rather sexy, although I know its not recommended. </p>
  
  <p>Is there a cleaner pattern to achieve this that does not hide away the application logic beneath lots of boilerplate code?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>As an example for the nature of the steps, the <code>Run</code> method could read</p>
  
  <pre><code>void Run()
  {
      GiantRobotor.MoveToBase();
      Oven.ThrowBaguetteTowardsBase();    
      GiantRobotor.CatchBaguette();
      // ...
  }
  </code></pre>
  
  <p>We are controlling different hardware units that need to be synchronized to work together.</p>