Awaiting an Asynchronous Operation

Windows Runtime APIs are designed to make it really hard to block a UI thread. Whenever the Windows Runtime exposes a potentially-long-running operation, it does so with an asynchronous method that performs its work on a background thread. You can easily identify such methods by their Async suffix. And they are everywhere. For example, showing a MessageDialog (discussed in Chapter 14, “Other Controls”) requires a call to ShowAsync:

MessageDialog dialog = new MessageDialog("Title"); IAsyncOperation<IUICommand> operation = dialog.ShowAsync(); // The next line of code runs in parallel with ShowAsync's background work MoreCode();

Asynchronous methods in the Windows Runtime return one ...

Get Universal Windows® Apps with XAML and C# Unleashed now with O’Reilly online learning.

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