Last active
July 31, 2020 14:48
-
-
Save ssa3512/1b1016ab616a8820d2172f97fbe360e3 to your computer and use it in GitHub Desktop.
Tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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