I wont be wrong if I think that await will release the calling thread but Task.Result will block it, would it be right?
Generally, yes. await task;
will “yield” the current thread. task.Result
will block the current thread. await
is an asynchronous wait; Result
is a blocking wait.
There’s another more minor difference: if the task completes in a faulted state (i.e., with an exception), then await
will (re-)raise that exception as-is, but Result
will wrap the exception in an AggregateException
.
As a side note, avoid Task.Factory.StartNew
. It’s almost never the correct method to use. If you need to execute work on a background thread, prefer Task.Run
.
Both Result
and StartNew
are appropriate if you are doing dynamic task parallelism; otherwise, they should be avoided. Neither is appropriate if you are doing asynchronous programming.