简体   繁体   English

“CS4014:由于未等待此调用,因此在调用完成之前继续执行当前方法”的最佳方法是什么?

[英]What's the best approach to "CS4014: Because this call is not awaited, execution of the current method continues before the call is completed"?

在此处输入图像描述

Visual Studio is showing this warning on every async task that I do not want to await . Visual Studio 在我不想等待的每个异步任务上都显示此警告。 Why?为什么? I don't want to globally suppress all these warnings, because there may be instances I forget to await, but most of the time when this warning appears, it's because I'm intentionally not awaiting a task.我不想全局禁止所有这些警告,因为可能有些情况我忘记等待,但大多数时候出现此警告,是因为我故意等待任务。 What's the best response to these warnings?对这些警告的最佳回应是什么?

The problem is that it is returning a task, so to not await, the best way is to just set the return to something such as:问题是它正在返回一个任务,所以不要等待,最好的方法是将返回设置为:

_ = SomeAwaitableTask();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM