public async Task Run() { Diag.PrintContext("ENTER"); await WorkWithoutCA(); Diag.PrintContext("EXIT"); }
private async Task DoWorkAsync(uint cycles) { Diag.PrintContext("ENTER"); await BlockingWorkAsync(cycles).PrintContext(); Diag.PrintContext("EXIT"); }
private async Task DoWorkAsyncCA(uint cycles) { Diag.PrintContext("ENTER"); await BlockingWorkAsyncCA(cycles).PrintContext().ConfigureAwait(false); Diag.PrintContext("EXIT"); }
public async Task Run() { // regular async calls with no use of ConfigureAwait(false) // will use the default synchronization context Diag.PrintContext("ENTER"); await WorkWithoutCA(); Diag.PrintContext("EXIT"); }
public async Task Run() { // async calls run on a completely different thread (which does // not capture the original SynchronizationContext) Diag.PrintContext("ENTER"); await Task.Run(() => WorkWithoutCA()); Diag.PrintContext("EXIT"); }
public async Task Run() { // async calls with all awaits marked with ConfigureAwait(false) // will try to not use the default synchronization context Diag.PrintContext("ENTER"); await WorkWithFullCA(); Diag.PrintContext("EXIT"); }
public async Task Run() { // async calls with just the initial method's awaits marked // with ConfigureAwait(false) // will try to not use the default synchronization context Diag.PrintContext("ENTER"); await WorkWithShallowCA(); Diag.PrintContext("EXIT"); }
private async Task WorkWithoutCA() { Diag.PrintContext("ENTER"); await DoWorkAsync(cycleCount).PrintContext(); await DoWorkAsync(cycleCount).PrintContext(); await DoWorkAsync(cycleCount).PrintContext(); Diag.PrintContext("EXIT"); }
private async Task WorkWithFullCA() { Diag.PrintContext("ENTER"); await DoWorkAsyncCA(cycleCount).PrintContext().ConfigureAwait(false); await DoWorkAsyncCA(cycleCount).PrintContext().ConfigureAwait(false); await DoWorkAsyncCA(cycleCount).PrintContext().ConfigureAwait(false); Diag.PrintContext("EXIT"); }
private async Task WorkWithoutCA() { Diag.PrintContext("ENTER"); await new SynchronizationContextRemover(); // this await strips the // SynchronizationContext for await DoWorkAsync(cycleCount).PrintContext(); // the rest of the this method await DoWorkAsync(cycleCount).PrintContext(); await DoWorkAsync(cycleCount).PrintContext(); Diag.PrintContext("EXIT"); }
private async Task WorkWithShallowCA() { // only has ConfigureAwait at this level, children do not. Diag.PrintContext("ENTER"); await DoWorkAsync(cycleCount).PrintContext().ConfigureAwait(false); await DoWorkAsync(cycleCount).PrintContext().ConfigureAwait(false); await DoWorkAsync(cycleCount).PrintContext().ConfigureAwait(false); Diag.PrintContext("EXIT"); }
private async Task BlockingWorkAsync(uint cycles) { // Perform both async blocking and synchronous blocking Diag.PrintContext("ENTER"); await Task.Delay(1000).PrintContext(); Thread.Sleep(1000); await Task.Delay(1000).PrintContext(); Diag.PrintContext("EXIT"); }