public void ResultReturned(object obj, ProgressChangedEventArgs args)
{
string msg = "Number of results considered:{0}";
msg = string.Format(msg, _resultCount);
_resultCount += 1;
Debug.WriteLine(msg);
Result<AmazonItem> result;
// Grab the result
if (args.UserState.GetType() == typeof(Result<AmazonItem>))
{
result = (Result<AmazonItem>)args.UserState;
// If we're already done, stop all threads
// still active and exit
if (IsWorkFinished())
{
HaltAllOngoingWork();
return;
}
ReportProgress(GetPercentComplete(), result);
// If it was a result that fit our search critera, update
// our counter (used by the GetPercentComplete method)
if (result.HasReturnValue) _validResultCount += 1;
}
}