In other words, is
var task = SomeLongRunningOperationAsync();
task.Wait();
functionally identical to
SomeLongRunningOper
Here are some differences:
AggregateException
. The exception stack will be different.HttpContext.Current
(which is not actually thread-local but almost), might be different.Task
induces a memory barrier why can have a synchronizing effect.Does this matter? Decide for yourself by this list.
Are there benefits to doing this? I can't think of any. If your computation uses async IO the wait will negate the benefits that the async IO brings. The one exception would be fan-out IO, e.g. issuing 10 HTTP requests in parallel and waiting for them. That way you have 10 operations at the cost of one thread.
Note, that Wait
and Result
are equivalent in all these regards.