Chapter 16, Asynchronous Programming
- Task-based asynchronous pattern.
CancellationToken.IProgress<T>.- An asynchronous method is declared, with the
asynckeyword preceding the method name. Theawaitkeyword precedes an asynchronous operation and prevents the continuation of any further code until the asynchronous operation is complete.Taskis what an asynchronous method returns. Forvoidmethods, the return type isTask, and for methods that return a value, the return type isTask<T>. - Create a new
CancelationTokenSourceand 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 theProgressChangedevent. Alternatively, you can pass a single handler into theProgress<T>constructor.