C# 如何使用等待语法从Windows.Devices.Enumeration.DeviceInformation.FindAllAsync读取结果?
我的计算机有一个可工作的智能卡读卡器,该读卡器应通过以下代码段返回:C# 如何使用等待语法从Windows.Devices.Enumeration.DeviceInformation.FindAllAsync读取结果?,c#,async-await,winmd,C#,Async Await,Winmd,我的计算机有一个可工作的智能卡读卡器,该读卡器应通过以下代码段返回: string selector = Windows.Devices.SmartCards.SmartCardReader.GetDeviceSelector(); Windows.Devices.Enumeration.DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(se
string selector = Windows.Devices.SmartCards.SmartCardReader.GetDeviceSelector();
Windows.Devices.Enumeration.DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selector);
但是,我遇到了以下错误:
错误CS4036“IAsyncOperation
”不包含“GetAwaiter
”的定义,并且找不到接受类型为“IAsyncOperation
”的第一个参数的扩展方法“GetAwaiter
”(是否缺少“系统
”的using指令?)
代码段是从中复制的
如何解决此错误?错误消息为您提供了一个很好的错误提示。添加
使用系统将代码>指令添加到文件顶部
为了便于将来参考,您可以通过在MSDN中搜索有问题的扩展方法(例如,搜索“IAsyncOperation GetWaiter扩展方法”)来自行查找。当我这样做时,第一个页面是,在该页面上,您可以看到该方法位于System
命名空间中,并在System.Runtime.WindowsRuntime.dll
程序集中定义。有了这两条信息,您可以再次检查,以确保您有使用系统,并且项目中有System.Runtime.WindowsRuntime.dll
程序集引用。错误消息为您提供了一个关于错误的非常好的提示。添加使用系统将代码>指令添加到文件顶部
为了便于将来参考,您可以通过在MSDN中搜索有问题的扩展方法(例如,搜索“IAsyncOperation GetWaiter扩展方法”)来自行查找。当我这样做时,第一个页面是,在该页面上,您可以看到该方法位于System
命名空间中,并在System.Runtime.WindowsRuntime.dll
程序集中定义。有了这两条信息,您可以再次检查,以确保您有使用系统,并且项目中有System.Runtime.WindowsRuntime.dll
程序集引用