I have an interface which will be implemented by multiple classes. The interface has a method that requires asynchronous calls with some implementations, but does not require asynchronous calls with the others. It looks something like this:
public interface IDoSomething
{
Task DoTheThing();
}
public class DoSomethingOnTheWeb : IDoSomething
{
public async Task DoTheThing()
{
// Do something that requires an async method, such as HttpClient.PostAsync()
}
}
public class DoSomethingLocally : IDoSomething
{
public async Task DoTheThing()
{
// Everything in this method can be done synchronously
}
}
DoSomethingLocally.DoTheThing doesn't have any await calls in it, so Visual Studio gives me a warning that I'm not awaiting anything inside an async method. Is there a clean way of handling this situation without either disabling the compiler warning or adding Task.Delay(0) to the method?