The C # compiler does not know how to correctly select the type of delegate in the case of an implicit type conversion to the delegate and method overload with different delegate parameters.
Specifically, in this case, the compiler mistakenly chooses an overload that accepts Func<Task> or Func<T> .
To circumvent this behavior, you can use
- type explicit cast:
await Task.Run((Action)Foo) - explicit delegate creation:
await Task.Run(new Action(Foo)) - or lambda expression:
await Task.Run(() => Foo())
PS It makes no sense to make methods consisting of a single await operator. It would be possible to remove the words async and await - nothing would have changed.
Actionshould helpTask.Run((Action)Foo)- Grundy