Pseudocode for async/await keywords

suggest change

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) =>
    {
        if (context == null)
            Qux();
        else
            context.Post((obj) => Qux(), null);
    }, TaskScheduler.Current);

    return t;
}

It means that async/await keywords use current synchronization context if it exists. I.e. you can write library code that would work correctly in UI, Web, and Console applications.

Source article.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Synchronization Context in Async/Await:
* Pseudocode for async/await keywords

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
112 Synchronization Context in Async/Await
127 Caching
135 Pointers
147 C# Script