AmazonScrape.SearchManager.ResultReturned C# (CSharp) Method

ResultReturned() public method

Called by the PageManagers whenever they have a result. Returns the result back to the UI. Also checks and stops work if finished.
public ResultReturned ( object obj, ProgressChangedEventArgs args ) : void
obj object sender object
args System.ComponentModel.ProgressChangedEventArgs Result
return void
        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;

            }
        }