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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.