[英]Async method signature error. Must return void, Task or Task<T>
I have an async method. 我有一个异步方法。
private static async Task InsertConnectionStatusIntoAzureDatabaseAsync(Device device)
{
...
}
I call it using 我叫它用
await InsertConnectionStatusIntoAzureDatabaseAsync(device).ConfigureAwait(false);
Visual studio will not build saying that an async method must return void, Task or Task<T>
Visual Studio不会构建说
async method must return void, Task or Task<T>
It also red squiggles the line InsertConnectionStatusIntoAzureDatabaseAsync(device).ConfigureAwait(false);
它也是红色曲线插入行
InsertConnectionStatusIntoAzureDatabaseAsync(device).ConfigureAwait(false);
saying : 说:
Task does not contain a definition for ConfigureAwait()
任务不包含ConfigureAwait()的定义
The usings at the top of the file are 文件顶部的用法是
using System.Threading.Tasks;
using System.Threading;
The .net framework it targets is 4.6.1 它所针对的.net框架是4.6.1
You almost certainly have another class in your project called Task
which is conflicting with the .Net Framework version. 您几乎肯定在您的项目中有另一个名为
Task
类,该类与.Net Framework版本冲突。 You can check this by going to the definition of the Task
type and see where it leads you. 您可以通过转到
Task
类型的定义来查看它,并查看它引导您的位置。 So either rename your version to something distinct (probably the best option) or use the full namespace: 因此,要么将您的版本重命名为不同的版本(可能是最佳选项),要么使用完整的命名空间:
private static async System.Threading.Tasks.Task InsertConnectionStatusIntoAzureDatabaseAsync()
{
//snip
}
You can as well use namespace alias and use that in your method signatire like 您也可以使用命名空间别名,并在方法签名中使用它
using task = System.Threading.Tasks;
private static async task.Task InsertConnectionStatusIntoAzureDatabaseAsync(Device device)
{
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.