Shouldn't "DoSomething" have a signature of type Func<object,Task>
as opposed to Action?
No - the method doesn't return anything. Look at the declaration - it's void
, not Task
. The async
part is just for the compiler's benefit (and humans reading it) - it's not really part of the signature of the method. An async method must return either void
, Task
, or Task<T>
- but the return type of the method really is just what you declare it to be. The compiler doesn't turn your void
into Task
magically.
Now you could write the exact same method body and declare the method as:
public async Task DoSomething(object arg){ ... }
at which point you would need to use Func<object, Task>
- but that's a different method declaration.
I would strongly advise you to use the form returning Task
unless you're using an async method to subscribe to an event - you might as well allow callers to observe your method's progress, failure etc.