private void StartBatchUrlCheck(ThreadedBindingList <MarketPlaceContent> boundList, SynchronizationContext threadToInvoke, DoWorkEventArgs e, BackgroundWorker worker) { int progressbarMax = 100; bgw.ReportProgress(0); if (NetworkDelay == 0) { bgw.ReportProgress(progressbarMax); return; } try { List <MarketPlaceContent> workingContent = boundList.ToList(); foreach (MarketPlaceContent oneContent in workingContent) { //e.argument is ForceRecheck true/false int DelayModifier = 40; //todo Math Over here, Fill progress bar with correct value int Delay = 1000 / DelayModifier; decimal InnerCount; decimal OuterCount = workingContent.IndexOf(oneContent) + 1; int InnerTotal = DelayModifier * Delay * NetworkDelay; int OuterTotal = workingContent.Count; int ProgressPercent = (int)Math.Ceiling(OuterCount / OuterTotal * progressbarMax); if (worker.CancellationPending && !(bool)e.Argument) { break; } if (!oneContent.DownloadChecked || (bool)e.Argument) { oneContent.CheckDownloadUrl(worker.CancellationPending, (bool)e.Argument); } else { bgw.ReportProgress(ProgressPercent); continue; } var elementAtOrDefault = boundList.ElementAtOrDefault(workingContent.IndexOf(oneContent)); if (elementAtOrDefault != null && elementAtOrDefault.TitleId == oneContent.TitleId) { //boundList.RaiseListChangedEvents = false; boundList[workingContent.IndexOf(oneContent)] = oneContent; //boundList.RaiseListChangedEvents = true; //threadToInvoke.Post(delegate { boundList.ResetItem(boundList.IndexOf(oneContent)); }, null); } bgw.ReportProgress(ProgressPercent); //networkdelay * 10 * sleep = TotalDelay if (oneContent.DownloadChecked || (bool)e.Argument) { if (!(workingContent.IndexOf(oneContent) >= workingContent.Count)) //Skip the Delay { //NetworkDelay is Delay as Int Value in Seconds for (int i = 0; i < NetworkDelay * DelayModifier; i++) { InnerCount = Delay * i; ProgressPercent = (int)Math.Ceiling((InnerCount + OuterCount * InnerTotal) / (InnerTotal * (OuterTotal + 1)) * progressbarMax); bgw.ReportProgress(ProgressPercent); if (worker.CancellationPending) { break; } Thread.Sleep(Delay); } if (worker.CancellationPending) { break; } } else { ProgressPercent = (int)Math.Ceiling((OuterCount + 1 / OuterTotal) * progressbarMax); } } } } catch (InvalidOperationException ex) { boundList.ResetBindings(); //Do Nothing Here, This Exception Is Intentional //And is Caused by allcontent being changed from user switching the page they are viewing Console.WriteLine(e.ToString()); throw; } }