Best practice to call ConfigureAwait for all server-side code

前端 未结 4 707
既然无缘
既然无缘 2020-11-22 04:06

When you have server-side code (i.e. some ApiController) and your functions are asynchronous - so they return Task - is it consid

4条回答
  •  名媛妹妹
    2020-11-22 04:10

    The biggest draw back I've found with using ConfigureAwait(false) is that the thread culture is reverted to the system default. If you've configured a culture e.g ...

    
            
        ...
    

    and you're hosting on a server whose culture is set to en-US, then you will find before ConfigureAwait(false) is called CultureInfo.CurrentCulture will return en-AU and after you will get en-US. i.e.

    // CultureInfo.CurrentCulture ~ {en-AU}
    await xxxx.ConfigureAwait(false);
    // CultureInfo.CurrentCulture ~ {en-US}
    

    If your application is doing anything which requires culture specific formatting of data, then you'll need to be mindful of this when using ConfigureAwait(false).

提交回复
热议问题