Creating a task wrapper around an existing object

后端 未结 3 1129
情书的邮戳
情书的邮戳 2021-01-03 20:32

I have a method which returns a Task where the implementation may or may not need to perform a slow operation in order to retrieve the result. I would like to be able to si

3条回答
  •  暖寄归人
    2021-01-03 21:06

    Beginning with .NET 4.5, you can use the Task.FromResult() static method for exactly this purpose:

    return Task.FromResult(_Cache[key]);
    

提交回复
热议问题