Synchronization Behavior

Asynchrony is a traditional source of interesting synchronization behavior due to the callbacks getting invoked upon completion of the operation (for example, on the thread pool). Without any manual synchronization to the context of the original caller of the asynchronous operation, all sorts of things can go bad. The most common example is attempting to update the UI from a callback, as shown in Figure 31.14.

Image

FIGURE 31.14 Cross-thread violations when updating the UI.

Just like the APM and the EAP, the TAP doesn’t require callbacks to happen in a particular context. When the task gets signaled—in ways discussed in the ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.