How to use async on an empty interface method
asynchronous, c#, syntax
Solution
Methods that return `Task` do not have to be `async`.
I would recommend something like this:
Task IFoo.SomeMethodAsync()
{
return Task.FromResult(true);
}
I'm assuming that if this was a synchronous method, you would just have an empty method body; this is the `async` equivalent of an empty method body.
Problem
Say I have an interface ``` interface IFoo { Task SomeMethodAsync(); } ``` And I wanted to implement this interface, but for one class the method is blank. Should I live with the warning this produces? ``` async Task SomeMethodAsync() {} ``` Or should I have it return some dummy task? ``` async Task SomeMethodAsync() { await Task.Run(() => {}); } ``` Or is there another option? Also I want to implement this method as an explicit interface method. Will that make any difference?