title: Thread synchronization with Task.ConfigureAwait(false)
body: <p>Consider the following code:</p>
  
  <pre><code>using System.IO;
  using System.Threading.Tasks;
  
  public class MyClass
  {
      private int count;
  
      public async Task&lt;int&gt; MyReadAsync(Stream stream, byte[] buffer)
      {
          var read = await
              stream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
          this.count += read;
          return read;
      }
  }
  </code></pre>
  
  <p>Let's assume that this <code>MyReadAsync</code> method is directly called from an event handler of a WPF application, as follows:</p>
  
  <pre><code>private async void OnWhatever(object sender, EventArgs args)
  {
      await myObject.MyReadAsync(this.stream, this.buffer);
  }
  </code></pre>
  
  <p>Here are my questions:</p>
  
  <ol>
  <li>Using <code>ConfigureAwait(false)</code> allows that the portion of the code that starts with the line <code>this.count += read;</code> can be executed on any threadpool thread, correct?</li>
  <li>For two separate calls of <code>MyReadAsync</code>, there is no guarantee that the portion of the code that starts with <code>this.count += read;</code> will be executed on the same thread, correct?</li>
  <li>If 1 &amp; 2 are correct, then it seems to me that the code <code>this.count += read;</code> should be protected with appropriate thread synchronization primitives, correct?</li>
  </ol>