Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Server Side Async, DEU Bilgisayar Topluluğu Izmir 2. Teknoloji Zirvesi (EN)

Server Side Async, DEU Bilgisayar Topluluğu Izmir 2. Teknoloji Zirvesi (EN)

* Slide template belongs to MIX 11 conference.
* A few parts of the content have been taken from other presentations (links to those presentations are available at the bottom-right corner for each slide).

Tugberk Ugurlu

January 06, 2013
Tweet

More Decks by Tugberk Ugurlu

Other Decks in Programming

Transcript

  1. ?

  2. Task1 Task 2 Task 3 1 2 3 4 5

    6 7 Call Started Waiting for the Operation to Complete (Blocked!) Other Tasks
  3. 1 2 8 9 5 6 7 Call Started Processing

    Other Tasks 3 4 Confimation for the Callback Task1 Task 2 Task 3
  4. async void button1_Click(…) { await DoWorkAsync(); } async void button1_Click(…)

    { DoWorkAsync().Wait(); } async Task DoWorkAsync() { await Task.Run(…); Console.WriteLine("Done task"); } 1. DoWorkAsync invoked on the main thread 3. Await captures SynchronizationContext and hooks up a continuation to run when task completes 4. Main thread blocks waiting for DoWorkAsync-returned Task to complete 6. UI thread still blocked waiting for async operation to complete. Deadlock! .ConfigureAwait(false) avoids deadlock. async Task DoWorkAsync() { await Task.Run(…).ConfigureAwait(false); Console.WriteLine("Done task"); } 2. Task.Run schedules work to run on thread pool 5. Task.Run task completes on pool & invokes continuation which Posts back to main thread