Progress Reporting

An additional parameter may be provided to report progress for the in-flight operation, using the IProgress<T> type. Just like the optional parameter to supply a CancellationToken, this parameter should appear after the operation’s core parameters. A null reference can be supplied by callers of the method to indicate no progress reports are desired. An example of a signature with progress reporting is shown here:

Task ProcessRecordsAsync(int categoryId, IProgress<int> progress);

This method could process a set of records from some store, matching the specified category identification number. The progress parameter allows tracking of the operation based on int values, which could denote the completion percentage. Callers of ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.