【发布时间】:2018-06-18 12:55:54
【问题描述】:
是否可以在 Acumatica(6.00.1263) PXLongOperation 块内使用基于 async/await 的方法?
当我尝试这个时,我得到了这个System.InvalidOperationException:
此时无法启动异步操作。异步操作只能在异步处理程序或模块内或在页面生命周期中的某些事件期间启动。如果在执行页面时发生此异常,请确保将页面标记为 。此异常还可能表示尝试调用“async void”方法,在 ASP.NET 请求处理中通常不支持该方法。相反,异步方法应该返回一个任务,调用者应该等待它。
我的代码如下所示:
PXLongOperation.StartOperation(this, async delegate ()
{
FooProcess graph = PXGraph.CreateInstance<FooProcess>();
await graph.ImportDocumentsAsync();
});
我也试过了:
PXLongOperation.StartOperation(this, delegate ()
{
FooProcess graph = PXGraph.CreateInstance<FooProcess>();
graph.ImportDocumentsAsync().GetAwaiter().GetResult();
});
我添加了一个可行的答案,但我希望有(或将会有)更好的方法来做到这一点,也许是不同的 API 或用于本地处理异步/等待的长操作的重载。
【问题讨论】:
标签: c# asynchronous acumatica