title: How do you get a working interaction with ConfigureAwait(true) in a console application?
body: <p>In a small project i am working on i have the neccessity for a component to execute a components shutdown code in the same thread that it was initialized in. However unlike in WPF/Winforms/Web the synchronizationcontext which takes care of this does not work.</p>
  <p>My guess is that the lack of a synchronization context is the issue that causes the lack of utilization for ConfigureAwait(true).</p>
  <p>Does someone know how to properly implement this?</p>
  <p>I read <a href="https://devblogs.microsoft.com/pfxteam/await-synchronizationcontext-and-console-apps/" rel="nofollow noreferrer">this</a> article but could not make any sense of it yet. Perhaps it was too late yesterday.</p>
  <p>Minimal Repro:</p>
  <pre><code>using System;
  using System.Threading;
  using System.Threading.Tasks;
  
  namespace ConsoleSyncContext
  {
      class Program
      {
          static async Task Main(string[] args)
          {
              Console.WriteLine($&quot;Thread: {Thread.CurrentThread.ManagedThreadId}&quot;);
              await SomeBackgroundWorkAsync();
              // if this is the same thread as above the question is solved.
              Console.WriteLine($&quot;Thread: {Thread.CurrentThread.ManagedThreadId}&quot;);
          }
  
          private static async Task SomeBackgroundWorkAsync()
          {
              await Task.Run(() =&gt; { });
          }
      }
  }
  
  </code></pre>