ConfigureAwait()をいつ使うべきかを理解しようとしています。予約する Accordin:ConfigureAwaitの理解
When an async method resumes after an await, by default it will resume executing within the same context. This can cause performance problems if that context was a UI context and a large number of async methods are resuming on the UI context.
Solution
To avoid resuming on a context, await the result of ConfigureAwait and pass false
for its continueOnCapturedContext parameter:
async Task ResumeWithoutContextAsync()
{
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
// This method discards its context when it resumes.
}
を
文脈とどのようにConfigureAwaitを(参照することです何が)サンプルアプリケーションで物事を変更します。
static async Task ResumeWithoutContextAsync()
{
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(true);
Console.WriteLine("ManagedThreadId {0}", Thread.CurrentThread.ManagedThreadId);
// This method discards its context when it resumes.
}
static void Main(string[] args)
{
ResumeWithoutContextAsync();
Console.ReadLine();
}
私はそのコンテキストを考えていたスレッドですが、そうではありません。
「ブロッキング」という用語があります。一部のメソッドは、作業が同期(ブロック)されたときに戻り、他のメソッドは非同期(非ブロック)であり、すべての作業が完了する前に戻ります。メソッドが非ブロッキングであり、すべての作業が完了するまで待つ必要がある場合は、待機する必要があります。 – jdweng
https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html – peco