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.