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 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.