【发布时间】:2018-07-31 21:13:45
【问题描述】:
我正在了解async 和await。我有一个用于对话消息的异步方法,我正在等待另一种方法。
我的代码=>
private async Task CalculateProcess()
{
dialogCoordinator = DialogCoordinator.Instance;
// Show...
ProgressDialogController controller = await dialogCoordinator.ShowProgressAsync(this, "HEADER", "MESSAGE");
controller.SetIndeterminate();
// Do your work...
await testing();//I want to await testing method but i cant await testing because testing method no return task
// Close...
await controller.CloseAsync();
}
private void testing()
{
for(int i=0;i<=1000000;i++)
{
}//Looping is example
}
我想等待测试方法,但是如果我想使用等待,我需要从测试中返回任务。如果我没有任何其他返回任务,我如何等待测试方法?
【问题讨论】:
-
这是另一个“如何异步调用同步方法”,虽然我找不到好的副本..这么多..
-
在这种情况下是什么阻止您更改方法签名?
-
谢谢,但这对我来说是无法理解的。
-
您可以随时将其包装在 Task.Run 中 - 详细信息如下:stackoverflow.com/questions/13071833/…
标签: c# async-await