async Task<int> LongTask1() {
...
return 0;
}
async Task<int> LongTask2() {
...
return 1;
}
...
{
Task<int> t1 = LongTask1();
Task<int> t2 = LongTask2();
await Task.WhenAll(t1,t2);
//now we have t1.Result and t2.Result
}
More Related Contents:
- async/await – when to return a Task vs void?
- WaitAll vs WhenAll
- Catch an exception thrown by an async void method
- Awaiting multiple Tasks with different results
- How to cancel a Task in await?
- Running multiple async tasks and waiting for them all to complete
- Calling async method synchronously
- What’s the difference between Task.Start/Wait and Async/Await?
- Why does this async action hang when I try and access the Result property of my Task?
- Best way in .NET to manage queue of tasks on a separate (single) thread
- Task sequencing and re-entracy
- Proper way to implement a never ending task. (Timers vs Task)
- Enforce an async method to be called once
- What’s the difference between returning void and returning a Task?
- awaitable Task based queue
- How does Task become an int?
- Best way to convert callback-based async method to awaitable task
- Is async HttpClient from .Net 4.5 a bad choice for intensive load applications?
- Executing tasks in parallel
- Calling async methods from non-async code
- Use Task.Run() in synchronous method to avoid deadlock waiting on async method?
- A pattern for self-cancelling and restarting task
- What is the correct way to cancel an async operation that doesn’t accept a CancellationToken?
- ForEachAsync with Result
- How can I capture the value of an outer variable inside a lambda expression?
- How to throttle multiple asynchronous tasks?
- Synchronous implementation of interface that returns Task
- Using async / await with DataReader ? ( without middle buffers!)
- How to implement Task.WhenAny() with a predicate
- Calling TaskCompletionSource.SetResult in a non blocking manner