Suppress warning CS1998: This async method lacks 'await'

前端 未结 14 979
遇见更好的自我
遇见更好的自我 2020-11-28 04:21

I\'ve got an interface with some async functions. Some of the classes that implements the interface does not have anything to await, and some might just throw. It\'s a b

14条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 05:01

    Another way to preserve the async keyword (in case you want to keep it) is to use:

    public async Task StartAsync()
    {
        await Task.Yield();
    }
    

    Once you populate the method you can simply remove the statement. I use this a lot especially when a method might await something but not every implementation actually does.

提交回复
热议问题