Skip to content

Instantly share code, notes, and snippets.

@ssa3512
Last active July 31, 2020 14:48
Show Gist options
  • Select an option

  • Save ssa3512/1b1016ab616a8820d2172f97fbe360e3 to your computer and use it in GitHub Desktop.

Select an option

Save ssa3512/1b1016ab616a8820d2172f97fbe360e3 to your computer and use it in GitHub Desktop.
Tasks
async Task Example1()
{
Task<SomeType1> task1 = DoSomethingAsync1();
Task<SomeType2> task2 = DoSomethingAsync2();
await Task.WhenAll(task1, task2);
SomeType1 result1 = task1.Result; // Should never use .Result in async methods?
SomeType2 result2 = task2.Result; // Should never use .Result in async methods?
// do something with results
}
async Task Example2()
{
Task<SomeType1> task1 = DoSomethingAsync1();
Task<SomeType2> task2 = DoSomethingAsync2();
await Task.WhenAll(task1, task2);
SomeType1 result1 = await task1; // Task has already been awaited?
SomeType2 result2 = await task2; // Task has already been awaited?
// do something with results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment