May 19th, 2021

Awaiting Windows Runtime asynchronous operations from C# desktop apps

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\
    10\
    UnionMetadata\
    (SDK version)\
    Windows.winmd

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\
    Microsoft\
    Framework\
    .NETCore\
    v4.5\
    System.Runtime.WindowsRuntime.dll

Okay, now you’re set up.

We’ll take this for a spin next time.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.

Feedback