C# 解决async Task<object>直接执行返回报“CS1998”警告

问题描述:

public async Task<bool> Login(string account, string password)
{
    return true;
}

此方法报:

CS1998;此异步方法缺少"await"运算符,将以同步方式运行。请考虑使用"await”"运算符等待非阻止的API调用,或者使用"await TaskRun(…)”在后台线程上执行占用大量CPU的工作。

在这里插入图片描述
解决方法:

public async Task<bool> Login(string account, string password)
{
    return await Task.FromResult(true);
}

关键字:

Task.FromResult(object);

你可能感兴趣的:(c#)