Synchronization Behavior of await Expressions

Asynchronous operations usually complete on a different thread than the one making the initial request to perform the operation. You’ve seen this repeatedly when studying the APM, EAP, and TAP patterns earlier in this chapter. This is a direct artifact from the way asynchronous completion of I/O operations is carried out on the thread pool. When dealing with compute bound asynchrony, the background thread that performed the computation will likely also be the one signaling the operation’s completion.

This decoupling from the requestor’s original context has traditionally posed an additional inconvenience, requiring manual synchronization for example to update the UI with the operation’s result. A ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.