private void RetrieveModulesForDisplay(object sender, DoWorkEventArgs e) { var processes = (IEnumerable <IProcess>)e.Argument; var worker = ((BackgroundWorker)sender); var processesCount = processes.Count(); var processedProcesses = 0; processes.ForEach(p => { if (worker.CancellationPending) { _view.CancelModulesViewUpdateFor(worker); e.Cancel = true; return; } _newModulesToShowByWorker[worker] = (Module[])(p.Modules().Where(m => !_modulesShownByWorker[worker].Contains(m)).ToArray().Clone()); if (worker.CancellationPending) { _view.CancelModulesViewUpdateFor(worker); e.Cancel = true; return; } _modulesShownByWorker[worker] = _modulesShownByWorker[worker].Union(_newModulesToShowByWorker[worker]).ToArray(); if (worker.CancellationPending) { _view.CancelModulesViewUpdateFor(worker); e.Cancel = true; return; } worker.ReportProgress(CalculateProgressPercentage(++processedProcesses, processesCount)); if (worker.CancellationPending) { _view.CancelModulesViewUpdateFor(worker); e.Cancel = true; return; } }); }