![](/img/trans.png)
[英]Should I use synchronous or asynchronous methods of c# mongodb driver?
[英]C# call synchronous methods from asynchronous methods
有没有办法从异步方法调用同步方法?
执行以下操作会导致编译器错误:
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
这里有哪些选项,是否可以添加注释以供编译器忽略?
谢谢!
通过深入查看文档,可以添加注释:
#pragma warning disable VSTHRD103
...
#pragma warning restore VSTHRD103
您可以参考下面给出的与此事件相关的链接,并且在这里他们asynchronously
调用synchronous
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.