Tutorial by Examples

Consider a simple asynchronous method: async Task Foo() { Bar(); await Baz(); Qux(); } Simplifying, we can say that this code actually means the following: Task Foo() { Bar(); Task t = Baz(); var context = SynchronizationContext.Current; t.ContinueWith(task...
To disable synchronization context you should call the ConfigureAwait method: async Task() Foo() { await Task.Run(() => Console.WriteLine("Test")); } . . . Foo().ConfigureAwait(false); ConfigureAwait provides a means to avoid the default SynchronizationContext capturi...
Consider this example: private void button1_Click(object sender, EventArgs e) { label1.Text = RunTooLong(); } This method will freeze UI application until the RunTooLong will be completed. The application will be unresponsive. You can try run inner code asynchronously: private void butt...

Page 1 of 1