Chapter 16. Asynchronous everywhere
This chapter covers
- Working with asynchronous operations
- Using async and await
- Using .NET Task and the WinRT IAsync* approaches
- Converting between WinRT IAsync* and Task
How many times have you used an application that became unresponsive, if only for a few seconds? Starting in Windows Vista, those applications would frost over and respond to clicks by shifting themselves a couple pixels on the screen. More often than not, those applications were executing some long-running function or were waiting for a resource to be freed. For example, my data drive is a low-power spinning rust drive, and it tends to be aggressive about spinning down. Sometimes, when I go to save a document in Microsoft Word, Word will frost over for a couple of seconds as the drive spins up and the data can be saved.[1]
1 My apps and Windows drive is on a big SSD that’s always in use and always responsive. If it starts requiring spin-up time, I’m in serious trouble.
In most UI frameworks, Windows applications have the concept of a UI thread which is where all interaction with the user happens. Windows Forms, WPF, and Silverlight drove that concept home to many by throwing an exception if code on a background thread attempted to access objects on the UI thread. When that thread is locked or busy for too long, you get an unresponsive application and the manifestations mentioned earlier.