{"id":105229,"date":"2021-05-19T07:00:00","date_gmt":"2021-05-19T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=105229"},"modified":"2021-05-19T05:45:11","modified_gmt":"2021-05-19T12:45:11","slug":"20210519-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20210519-00\/?p=105229\/","title":{"rendered":"Awaiting Windows Runtime asynchronous operations from C# desktop apps"},"content":{"rendered":"<p>Some time ago, I showed <a title=\"How do I get the computers serial number? Consuming Windows Runtime classes in desktop apps, part 4: C#\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20180109-00\/?p=97745\"> how to use Windows Runtime objects from C# desktop apps<\/a>. But that solution only went part of the way. It gave you access to the objects, but it didn&#8217;t provide a way to <code>await<\/code> any asynchronous operations.<\/p>\n<p>Let&#8217;s fill in that gap.<\/p>\n<p>Create a new <i>Console App (.NET Framework)<\/i> project from Visual Studio. This time, go to the References node, click <i>Add Reference<\/i> and click the <i>Browse<\/i> button. Change the file type filter to <i>All files<\/i> and pick<\/p>\n<pre>C:\\Program Files (x86)\\\r\n    Windows Kits\\\r\n    10\\\r\n    UnionMetadata\\\r\n    (SDK version)\\\r\n    Windows.winmd\r\n<\/pre>\n<p>This gets you access to the Windows Runtime classes, but it doesn&#8217;t enable <code>await<\/code> support. To do that, you also need to add<\/p>\n<pre>C:\\Program Files (x86)\\\r\n    Reference Assemblies\\\r\n    Microsoft\\\r\n    Framework\\\r\n    .NETCore\\\r\n    v4.5\\\r\n    System.Runtime.WindowsRuntime.dll\r\n<\/pre>\n<p>Okay, now you&#8217;re set up.<\/p>\n<p>We&#8217;ll take this for a spin next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Need to find the awaiter.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-105229","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Need to find the awaiter.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=105229"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105229\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=105229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=105229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=105229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}