Fine-Tuning Your Async Application (C# and Visual Basic)
You can add precision and flexibility to your async applications by using the methods and properties that the Task type makes available. The topics in this section show examples that use CancellationToken and important Task methods such as Task.WhenAll and Task.WhenAny.
By using WhenAny and WhenAll, you can more easily start multiple tasks and await their completion by monitoring a single task.
WhenAny returns a task that completes when any task in a collection is complete.
For examples that use WhenAny, see Cancel Remaining Async Tasks after One Is Complete (C# and Visual Basic) and Start Multiple Async Tasks and Process Them As They Complete (C# and Visual Basic).
WhenAll returns a task that completes when all tasks in a collection are complete.
For more information and an example that uses WhenAll, see How to: Extend the Async Walkthrough by Using Task.WhenAll (C# and Visual Basic).
This section includes the following examples.
To run the examples, you must have Visual Studio 2012, Visual Studio 2013, Visual Studio Express 2012 for Windows Desktop, Visual Studio Express 2013 for Windows, or the .NET Framework 4.5 or 4.5.1 installed on your computer.
The projects create a UI that contains a button that starts the process and a button that cancels it, as the following image shows. The buttons are named startButton and cancelButton.
You can download the complete Windows Presentation Foundation (WPF) projects from Async Sample: Fine Tuning Your Application.