Chapter 16, Asynchronous Programming
- Task-based asynchronous pattern.
CancellationToken
.IProgress<T>
.- An asynchronous method is declared, with the
async
keyword preceding the method name. Theawait
keyword precedes an asynchronous operation and prevents the continuation of any further code until the asynchronous operation is complete.Task
is what an asynchronous method returns. Forvoid
methods, the return type isTask
, and for methods that return a value, the return type isTask<T>
. - Create a new
CancelationTokenSource
and then set the method of cancelation, such asCancelAfter(3000)
. - Pass an
IProgress<T>
type into an asynchronous method as a parameter and add event handlers for theProgressChanged
event. Alternatively, you can pass a single handler into theProgress<T>
constructor.