When await is encountered, the control passes to the caller while awaited call waits for response.
Before control is passed to caller, the synchronization context is stored.
In case of windows app the synchronization context is the main UI thread. Thus when the await is complete, the saved context is restored and the rest of the code below the await executes with the original synchronization context.
I want to ask- what all items are stored in the synchronization context. For example:
Current thread
Local variable values
What else?
There is nothing stored in the SynchronizationContext. The SynchronizationContext is itself captured and stored by the asynchronous state machine, and used at the right moment by invoking its Post method. The local state is stored in the asynchronous state machine, along with the captured context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With