You are developing a Windows Store app.
The following code is provided as part of an RSS feed reader.
Correct Answer:
Explanation/Reference:
Note:
* IAsyncOperationWithProgress<TResult, TProgress> interface
Represents an asynchronous operation that includes progress updates.
* AsyncInfo.Run<TResult, TProgress> Method (Func<CancellationToken, IProgress<TProgress>, Task<TResult>>)
Creates and starts a Windows Runtime asynchronous operation that includes progress updates, by using a function that generates a started task that returns results. The task can support cancellation and progress reporting.
* Example:
The AsyncInfo class is there to assist you with performing asynchronous actions or operations that support cancellation and reporting progress.
public static IAsyncOperationWithProgress<int, double> Multiply(int a, int b)
{
return AsyncInfo.Run<IList<long>, double>((token, progress) =>
Task.Run<int>(() =>
{
progress.Report(0);
var result = a*b;
token.ThrowIfCancellationRequested();
progress.Report(100.0);
return result;
}, token));
}