Task.Run
may post the operation to be processed at a different thread. That's the only difference.
This may be of use - for example, if LongProcess
isn't truly asynchronous, it will make the caller return faster. But for a truly asynchronous method, there's no point in using Task.Run
, and it may result in unnecessary waste.
Be careful, though, because the behaviour of Task.Run
will change based on overload resolution. In your example, the Func<Task>
overload will be chosen, which will (correctly) wait for LongProcess
to finish. However, if a non-task-returning delegate was used, Task.Run
will only wait for execution up to the first await
(note that this is how TaskFactory.StartNew
will always behave, so don't use that).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…