4

Awaiting Windows Runtime asynchronous operations from C# desktop apps

 3 years ago
source link: https://devblogs.microsoft.com/oldnewthing/20210519-00/?p=105229
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Awaiting Windows Runtime asynchronous operations from C# desktop apps

Raymond Chen

Raymond

May 19th, 2021

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK