问题标签 [iasyncoperation]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
4191 浏览

c# - How to async / await in Renci.SshNet.BeginDownload with Task.Factory.FromAsync

I have access to a Connected Renci.SshNet.SftpClient which I use to get a sequence of the files in the sftp folder. The function used for this is

Due to the huge amount of files in the directory this takes about 7 seconds. I want to be able to keep my UI responsive using async / await and a cancellationToken.

If Renci.SshNet had a ListDirectoryAsync function that returned a Task, then this would be easy:

Alas the SftpClient doesn't have an async function. The following code works, however it doesn't cancel during the download:

However, the SftpClient does have kind of an async functionality using the functions

In the article Turn IAsyncResult code into the new async and await Pattern is described how to convert an IAsyncResult into an await.

However I don't have a clue what to do with all the parameters in the BeginListdirectory and where to put the EndListDirectory. Anyone able to convert this into a Task on which I can wait with short timeouts to check the cancellation token?

0 投票
0 回答
586 浏览

c# - Win10 BLE桌面应用IAsyncOperation作为集合

我正在升级桌面应用程序以在支持 BLE 的 Windows 10 上运行。我修改了应用程序以定位到相应的 Windows 版本,如本问题(如何在控制台中引用 Windows 8 运行时)中所述。现在尝试像本示例中那样一步一步地进行操作(Using BLE GATT services with Windows 10)。首先,我需要运行 ble scan,如下所示:

但是在编译时我得到与foreach循环相关的错误,这是错误:

错误 CS1579 foreach 语句无法对“Windows.Foundation.IAsyncOperation”类型的变量进行操作,因为“Windows.Foundation.IAsyncOperation”不包含“GetEnumerator”的公共定义

0 投票
2 回答
863 浏览

c# - AsAsyncAction VS Task.Run

每当我必须启动并行任务时,我通常会这样做:

但是通常我看到其他编码器使用AsAsyncOperation

与使用全新的 async/await 相比,有没有人知道 AsAsyncAction 带来了什么好处?

0 投票
1 回答
771 浏览

c# - 如何停止导致 IAsyncOperation 的呼叫?

在我的应用程序中,我通知多个设备。如果设备无法访问并且在几秒钟内没有响应,我想取消通话。

我的代码是:
await characteristic0.WriteClientCharacteristicConfigurationDescriptorAsync (GattClientCharacteristicConfigurationDescriptorValue.Notify);

现在经过一些研究,我发现通常可以通过CancelationToken (_ct) 并执行以下操作:

首先创建一个包含调用的操作:
IAsyncOperation<GattCommunicationStatus> operation = characteristic0.WriteClientCharacteristicConfigurationDescriptorAsync (GattClientCharacteristicConfigurationDescriptorValue.Notify);

然后使用 CancellationToken 创建一个任务:
Task<GattCommunicationStatus> task = operation.AsTask(_ct);

然后等待它:
GattCommunicationStatus status = await task;

现在,即使CancellationToken的IsCancellationRequested -Property设置为 true,情况也是如此。通话不会停止。而且,设备已经在第一行之后 得到通知!这不应该在调用之后发生吗?
await

我对令牌犯了错误还是这是更大的事情?

编辑
在与@Andrii Litvinov 交谈后,我在我最初对问题的描述中添加了一些代码。这是整个方法:

0 投票
0 回答
398 浏览

android - Android in app billing 无法启动异步操作

我是 android 新手,我的第一个应用程序最近完成了。我想在我的应用程序中设置一个 IAB(应用程序内计费),我测试了我的应用程序并且遇到了以下问题: 1-当我点击“购买”按钮时,一切正常并且支付操作正常运行。但是当我关闭应用程序并单击按钮时,出现以下错误。

2-我还有一个问题 :) 当某人购买我的应用程序时,如何更改按钮背景(例如将其测试从购买更改为阅读)

我该如何修复它们... tnx 高级。

0 投票
1 回答
651 浏览

c++ - 在 C++ WinRT 中无法获取异步操作结果(Windows::Foundation::IAsyncOperation 接口)

我有点绝望地试图获得带有Windows::Foundation::IAsyncOperation接口的 winrt 异步方法的结果。该项目是启用了 winRT 扩展的 Visual Studio Community 2017 c++ 项目。我试过使用std::future/co_await函数和任务方法,但调用GetResults()总是生成“在意外时间调用”异常。

使用以下代码,我没有得到异常但GetResults()返回nullptr。我也尝试在代码中声明async_op为 ashared_ptr auto async_op = std::make_shared<Windows::Foundation::IAsyncOperation<Windows::Devices::Bluetooth::BluetoothLEDevice^> ^> 并访问它,但我得到了相同的结果。*async_opHandler

欢迎任何想法。

提前致谢。

0 投票
0 回答
80 浏览

outlook - Outlook 作为放置目标是否支持 IAsyncOperation?

我正在玩从无到有,异步地创建一些东西[改进了.NET 的开发人员友好的虚拟文件实现!]

这篇精彩的文章演示了如何创建一个自定义的 DataObject,实现在拖放/粘贴上的延迟数据提取和在后台线程上的异步数据传输。

在我尝试将文件放入 Outlook 2016 之前,它运行良好。它仍然有效,但 UI 没有响应,尽管我的数据对象已将“IsAsynchronous”设置为 true。

调试后,我发现当拖放到 Outlook 时,未调用 IAsyncOperation.GetAsyncMode 并且在 UI 线程上调用了 IDataObject.GetData。

我的问题是 Outlook 是否支持 IAsyncOperation?如果它确实我错过了什么?如果它不支持 IAsyncOperation,是否有解决方法或不同的解决方案?

问候

0 投票
1 回答
1980 浏览

c# - IAsync 操作>' 不包含 'GetAwaiter' 的定义

我正在使用 Visual Studio 2017 Professional。

我一直在关注本指南: https ://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener

我的问题代码如下:

问题在于这一行:

这给出了错误:

'IAsyncOperation<IReadOnlyList<UserNotification>>'不包含“GetAwaiter”的定义,并且找不到接受第一个类型参数的扩展方法“GetAwaiter” 'IAsyncOperation<IReadOnlyList<UserNotification>>'(您是否缺少“System”的 using 指令?)

我已经尝试了所有我可以在网上找到的东西,从添加对以下内容的引用:

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
  • C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD

添加 NuGet 包:

  • Uwp桌面
  • Microsoft.NETCore.UniversalWindowsPlatform

重新安装 VS 并尝试不同版本的 SDK。

我真的不知道是什么导致了这个问题,我将非常感谢任何正确方向的指示。

0 投票
1 回答
442 浏览

c++ - 在 UWP 中使用 IAsyncOperation 继续任务

我有一个 c++ 类对象,它在 uwp 应用程序的后台执行一些处理。

它的进程操作由 Unity 的“更新”方法调用 ~60fps 通过 UWP IAsyncOperation

该类有一个isBusy属性,该属性true在调用操作后设置为,以便在它完成之前阻止它再次从统一调用。

使用任务继续,我想在处理完成后将其设置为 false 并通过IAsyncOperation.

我期望发生的事情是将ResultWrapper对象返回到调用应用程序(Unity)的主线程,然后isBusy任务继续将对象的标志设置为 false。

会发生什么:

0 投票
1 回答
54 浏览

uwp - 在 C++/UWP 中创建任务

我正在尝试在 VS2019 UWP C++ 中创建一个任务。我有这段代码:

我想要做的是有一个无限循环,在 Noop 所在的地方定期进行帧处理。此代码编译但抛出异常并声称这是 NULL。也许我没有为 lambda 提供返回值?欢迎任何建议。谢谢