c# async method and return await

后端 未结 1 1740
伪装坚强ぢ
伪装坚强ぢ 2021-01-24 11:13

one simple question. I found some methods with this \"logic\" and \"architecture\".

public async Task FindAsync(params object[] keys)
{
    return await         


        
相关标签:
1条回答
  • 2021-01-24 11:48

    If you're calling this method like this:

    await FindAsync(); // this method waits for the task to complete
    

    Then it doesn't make any sense to return await inside this method, you can just change it to:

    public Task<T> FindAsync(params object[] keys)
    {
        return this.context.FindAsync(keys); // Start and return the task
    }
    

    Then the caller awaits the task to Complete.

    0 讨论(0)
提交回复
热议问题