最后一个方法行上的Task.ConfigureAwait(false)是否会影响任何内容?

Pay*_*mon 4 wpf multithreading task task-parallel-library async-await

我知道在正在等待的任务上调用ConfigureAwait(false)有时会产生性能优势,因为它可以防止不必要的返回原始SynchroniZationContext.

例如:

async Task Something()
{
   // Let's say I'm on the UI context
   //...
   await AnotherTask.ConfigureAwait(false);

   // Code here is no longer running on the UI context.
   // It runs in a thread pool synchronization context (i.e. null).
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:如果任务调用在方法的最后一行,并且我们跳过ConfigureAwait(false),编译器是否足够智能以防止不必要地返回到原始上下文?

async Task Something()
{
   // Let's say I'm on the UI context
   //...
   await AnotherTask; // Dropped -> .ConfigureAwait(false);        
}
Run Code Online (Sandbox Code Playgroud)

即使在等待调用之后方法中没有任何内容,这里是否会存在性能损失潜在的死锁

Ste*_*ary 7

编译器是否足够智能以防止不必要的返回原始上下文?

还没.

即使在等待调用之后方法中没有任何内容,这里是否会存在性能损失或潜在的死锁?

是.