title: C# - Program execution flow yield/pause/resume
body: <p>Could you tell me please if there is a way in C# to pause and resume the program execution flow as I would like to do below? </p>
  
  <p>Or do you have an idea how to save/load the current thread call stack?</p>
  
  <p>I am looking for a solution that does not creates new thread at all.</p>
  
  <pre><code>public class MyClass : InterruptableClass
  {
      int x;
  
      public void Fn1()
      {
          x = 1;
          this.Interrupt();
          x = 2;
      }
  }
  
  static class Program
  {
      static void Main()
      {
          MyClass c = new MyClass();
  
          c.Fn1();
          // Now c.x is 1
  
          if (c.IsInterrupted)
          {
              c.ResumeExecution();
              // Now c.x is 2
          }
      }
  }
  </code></pre>
  
  <p>Unfortunately I cannot save / reload the call stack (StackTrace/StackFrame).</p>