Chapter 2. Why Programs Need to Be Asynchronous
Asynchronous programming is important and useful, but the reason that it’s important varies, depending on what kind of application you’re writing. Some of the benefits exist everywhere, but matter most in a kind of application that you may never write. If this applies to you, do read the whole chapter, as the background knowledge will help you to understand the whole context.
Desktop User Interface Applications
Desktop applications have one primary performance requirement. They need to feel responsive to the user. Human Computer Interaction (HCI) studies have shown that users don’t notice a slow application, as long as the interface is responsive, and preferably has an animated progress indicator.
People get frustrated with the program when it freezes up. Freezes are usually the result of the program being unable to respond to user input during a long-running operation, whether that’s during a slow computation, or during some input/output (IO) operation, like a network access.
The UI frameworks that you might use from C# all operate using a single UI thread. This includes:
WinForms
WPF
Silverlight
That UI thread is the only one that can control the contents of a particular window. It is also the only thread that checks for user actions and responds to them. If the thread is ever busy or blocked for more than a few tens of milliseconds, users will notice that the application feels sluggish.
Asynchronous code, even written manually, means that ...
Get Async in C# 5.0 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.