Asynchronous Read and Write Operations

All the I/O operations explained in the previous sections have been of the synchronous kind, meaning the caller is blocked until the data becomes available. Often, it’s more appropriate to read or write data asynchronously, to prevent hangs of user interface (UI) threads and to increase scalability of services. The essential idea of asynchronous I/O is to start the request and get notified when the action has been completed.

This section examines how the Stream class supports this modus operandi. Even though C# 5.0 introduces a new improved way to deal with asynchronous operations (discussed in great lengths in Chapter 31, “Asynchronous Programming”), we’ll start off by explaining the old Asynchronous Programming ...

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.