I have a simple set of code where I'm trying to implement an interface with an async method on it. The implementations thus far have all been things that utilize the async part of it and end up awaiting things. However, this new implementation of the interface is a simple synchronous operation-- no need for any awaiting.
When I implement it, first of all feels weird. Second, Visual Studio affirms my uncomfort with a warning telling me that the method is going to run synchronously-- which is what I'd expect, but the warning tells me it smells bad to VS, too. Is there a better pattern I should be following?
public interface IActivity
{
async Task<bool> DoStuff();
}
//...
List<IActivity> activities = new List<IActivity>(){
new SynchronousActivityA(),
new SynchronousActivityB(),
new AsynchronousActivityC()
};
foreach (var activity in activities){
bool stuff = await activity.DoStuff();
//do things with stuff.
}
I could just make my DoStuff() implementation do something like this:
await Task.Run(() => DoStuffSynchronously());
This would make my warning go away and feel a little more "right", but I'm not sure what benefit this would have over just writing the DoStuff() implementation to be as though it was a synchronous signature.