gpt4 book ai didi

c# - 如何使用等待语法从 Windows.Devices.Enumeration.DeviceInformation.FindAllAsync 读取结果?

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:53 36 4
gpt4 key购买 nike

我的电脑有一个工作的智能卡读卡器,应该由下面的代码片段返回:

string selector = Windows.Devices.SmartCards.SmartCardReader.GetDeviceSelector();
Windows.Devices.Enumeration.DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selector);

但是,我收到了这个错误:

Error CS4036 'IAsyncOperation<DeviceInformationCollection>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<DeviceInformationCollection>' could be found (are you missing a using directive for 'System'?)

代码片段复制自Microsoft's C# Sample Code

我该怎么做才能解决这个错误?

最佳答案

错误消息很好地提示了错误所在。将 using System; 指令添加到文件顶部。

为了将来引用,您可以通过在 MSDN 中搜索有问题的扩展方法来自行追踪,例如搜索“IAsyncOperation GetAwaiter 扩展方法”。当我这样做时,第一页是 WindowsRuntimeSystemExtensions.GetAwaiter Method (IAsyncOperation) ,在该页面上,您可以看到该方法位于 System 命名空间中,并在 System.Runtime.WindowsRuntime.dll 程序集中定义。有了这两条信息,您可以仔细检查以确保您的 .cs 文件中有 using System;,并且您有 System.Runtime.WindowsRuntime.dll 项目中的程序集引用。

关于c# - 如何使用等待语法从 Windows.Devices.Enumeration.DeviceInformation.FindAllAsync 读取结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38364683/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com