Note that there are some explanatory texts on larger screens.

plurals
  1. POAsync/Await: Unexpected behaviour of ConfigureAwait
    text
    copied!<p>If you execute the following code in ASP.NET MVC, you can see in Debugging Window that it will correctly restore the thread's culture after <code>await</code>, even if ManagedThreadId changes:</p> <pre><code>public async Task&lt;ActionResult&gt; Index() { Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE"); Debug.WriteLine(Thread.CurrentThread.ManagedThreadId); Debug.WriteLine(Thread.CurrentThread.CurrentUICulture); await SomeMethod(); Debug.WriteLine(Thread.CurrentThread.ManagedThreadId); Debug.WriteLine(Thread.CurrentThread.CurrentUICulture); return View(); } private async Task SomeMethod() { await Task.Delay(100).ConfigureAwait(false); } </code></pre> <p>Then I just move ConfigureAwait(false) from SomeMethod() to Index(), except for this, it's the same code as above:</p> <pre><code>public async Task&lt;ActionResult&gt; Index() { Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE"); Debug.WriteLine(Thread.CurrentThread.ManagedThreadId); Debug.WriteLine(Thread.CurrentThread.CurrentUICulture); await SomeMethod().ConfigureAwait(false); Debug.WriteLine(Thread.CurrentThread.ManagedThreadId); Debug.WriteLine(Thread.CurrentThread.CurrentUICulture); return View(); } private async Task SomeMethod() { await Task.Delay(100); } </code></pre> <p>Now it doesn't restore my culture but always set it to <code>new CultureInfo("en-US")</code>. But I expect that using both methods, the result must be the same. It's absolutely unclear, why it's happening.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload