title: What is the purpose of IAsyncStateMachine.SetStateMachine?
body: <p>Interface <code>IAsyncStateMachine</code> can be used only by compiler, and is used in generating state machine for async methods. Interface has <code>SetMachineState</code> - configures the state machine with a heap-allocated replica(from msdn).</p>
  
  <p>I used <code>ILSpy</code> to decompile code and discover generated state machine and mentioned that implementation of <code>SetMachineState</code> function is always empty, like this</p>
  
  <pre><code>[CompilerGenerated]
  private sealed class &lt;GetResult&gt;d__1 : IAsyncStateMachine
  {
      //some fields to hold state
  
      void IAsyncStateMachine.MoveNext()
      { ... }
  
      [DebuggerHidden]
      void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
      {
          //Method is empty
      }
  }
  </code></pre>
  
  <p>One more thing, generated state machine is a <code>class</code> not a <code>struct</code> as stated everywhere.</p>
  
  <p>So, the question is: What the purpose of <code>SetStateMachine</code> function of <code>IAsyncStateMachine</code> interface, where is it used?</p>
  
  <p>Original async function:</p>
  
  <pre><code>private static async Task&lt;int&gt; GetResult()
  {
      var task = GetSomeData();
      DoSomeWork();
      return await task;
  }
  </code></pre>