【发布时间】:2018-12-06 20:42:59
【问题描述】:
我了解在异步方法中不能使用 out 和 ref。但我不清楚使用 Action(或委托)的后果。虽然我认识到 Action 中设置的值可能要等到 await 之后才可用,但下面还有其他问题吗?他们的线程问题吗?我对此进行了广泛的谷歌搜索,但在任何地方都找不到明确的答案。
protected async Task<gPeriod> MapPeriod(string value, Action<int> setOutput)
{
(...) //omitted code
int x = await MyMethodAsync(value)
setOutput(x);
return gPeriod; //calculation of this not shown in this example
}
【问题讨论】:
-
问题中的代码本身没有任何错误或危险。
-
你的代码没问题。
标签: c# asynchronous async-await delegates action