有沒有辦法從異步呼叫同步方法?
執行以下操作會導致編譯器錯誤:
DoSomething synchronously blocks. Await DoSomethingAsync instead
public async Task<int> DoStuff(bool runAsync) {
int result;
if (runAsync) {
result = await DoSomethingAsync();
} else {
result = DoSomething();
}
return result;
}
可能有關系?https://github.com/microsoft/vs-threading/issues/541
這里有哪些選項,是否可以添加注釋供編譯器忽略?
謝謝!
uj5u.com熱心網友回復:
您可以參考下面給出的與此事件相關的鏈接,也可以在這里呼叫synchronous方法asynchronously。
https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously
uj5u.com熱心網友回復:
通過更深入地查看檔案,可以添加注釋:
#pragma warning disable VSTHRD103
...
#pragma warning restore VSTHRD103
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/363608.html
上一篇:哪個datetime.TryParseExact函式將支持C#.Net中像“2021-11-2111:34:45.234567 0000”這樣的格式?[復制]
