Awaiting Windows Runtime asynchronous operations from C# desktop apps

Raymond Chen

Some time ago, I showed how to use Windows Runtime objects from C# desktop apps. But that solution only went part of the way. It gave you access to the objects, but it didn’t provide a way to await any asynchronous operations.

Let’s fill in that gap.

Create a new Console App (.NET Framework) project from Visual Studio. This time, go to the References node, click Add Reference and click the Browse button. Change the file type filter to All files and pick

C:\Program Files (x86)\
    Windows Kits\
    (SDK version)\

This gets you access to the Windows Runtime classes, but it doesn’t enable await support. To do that, you also need to add

C:\Program Files (x86)\
    Reference Assemblies\

Okay, now you’re set up.

We’ll take this for a spin next time.