Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用等待任务时,Async方法无法返回void。运行_C# - Fatal编程技术网

C# 使用等待任务时,Async方法无法返回void。运行

C# 使用等待任务时,Async方法无法返回void。运行,c#,C#,我的代码如下所示: public async Task<T> GetSomeValue() { //Your function body to return an object of type T. } private ICommand aBtnCmd; private ICommand resetBtnCmd; public ICommand ABtnCmd => aBtnCmd ?? (aBtnCmd = new Comman

我的代码如下所示:

    public async Task<T> GetSomeValue()
    { 
        //Your function body to return an object of type T.
    }

private ICommand aBtnCmd;
private ICommand resetBtnCmd;

public ICommand ABtnCmd => aBtnCmd ?? (aBtnCmd = new Command(() => phrasesFrame.Btn((int)Settings.aBtn, 1)));
public ICommand ResetBtnCmd => resetBtnCmd ?? (resetBtnCmd = new Command(async () => await phrasesFrame.RBtn()));
async public Task Btn(int pts, int col)
{
    Change.points = true;
    await Task.Run(() => App.DB.IncrementPoints(Settings.cfs, phrase, pts, col));
}

async public Task RBtn()
{
    await Messages.ResetButtonClicked();
}
方法:

private ICommand aBtnCmd;
private ICommand resetBtnCmd;

public ICommand ABtnCmd => aBtnCmd ?? (aBtnCmd = new Command(() => phrasesFrame.Btn((int)Settings.aBtn, 1)));
public ICommand ResetBtnCmd => resetBtnCmd ?? (resetBtnCmd = new Command(async () => await phrasesFrame.RBtn()));
async public Task Btn(int pts, int col)
{
    Change.points = true;
    await Task.Run(() => App.DB.IncrementPoints(Settings.cfs, phrase, pts, col));
}

async public Task RBtn()
{
    await Messages.ResetButtonClicked();
}
有没有人能给我一些建议,告诉我如何从这些方法中恢复

我问这个问题的原因是,当我将鼠标悬停在异步字上时:

新命令异步

然后IDE发出一条消息,说明:


异步方法'您可以使用任务的通用版本返回某些内容

Task<T>
其中T是要返回的对象的类型

您的方法如下所示:

    public async Task<T> GetSomeValue()
    { 
        //Your function body to return an object of type T.
    }

给出这些示例,您建议我返回什么?调用Task.Run返回什么。在这里,您还可以使用函数的通用版本来指定实际方法返回的对象的类型。您希望异步运行这些方法有什么特殊原因吗?它们需要很长时间吗?您是否有实际错误,或者这只是一个警告?您的第二个lambda是一个异步void,但这在这里没有问题。