0

In the Task Parallel Library, or the TPL in .NET, when using asynchronous operations, there seems to be two ways to await the completion of the task:

If you have this...

Task<int> intReturningTask = Task.Factory.StartNew(() => IntReturningFunc() );

You can await it with this...

int x = await intReturningTask;

but I believe you can also await it like this...

int y = intReturningTask.Result;

My question is is there a difference between the two? My guess is 'no' and that await exists for the non-generic version of Task which doesn't have a result, but that's just speculation.

Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
  • `.Result` isn't `await`ing, it is blocking. The non-generic `Task` has `Task.Wait()` which is the same as `.Result` but without a result. – Lukazoid Apr 26 '16 at 22:11
  • Duplicate? http://stackoverflow.com/questions/24623120/await-on-a-completed-task-same-as-task-result – Timothy Kanski Apr 26 '16 at 22:12
  • You also never want to use .Result anyhow, but its twin GetAwaiter().GetResult() and even that extremely rarely. – Voo Apr 26 '16 at 22:25

0 Answers0