public async Task AmbientState() { var classWithAmbientState = new ClassWithAmbientState(); var tasks = new Task[3]; for (int i = 0; i < 3; i++) { tasks[i] = ((Func <Task>)(async() => { classWithAmbientState.Do(); await Task.Delay(200).ConfigureAwait(false); classWithAmbientState.Do(); }))(); } await Task.WhenAll(tasks); }
public async Task AmbientState() { var classWithAmbientState = new ClassWithAmbientState(); var tasks = new Task[3]; for (int i = 0; i < 3; i++) { tasks[i] = Task.Run(() => { classWithAmbientState.Do(); Thread.Sleep(200); classWithAmbientState.Do(); }); } await Task.WhenAll(tasks); }