void Form1_DoWork(object sender, DoWorkEventArgs e, int i) { ScrapingWorker worker; string Link; while (!String.IsNullOrEmpty(Link = ListsEncapsulation.IsAnyLeft())) { lock (Link) { textBoxList.Text += "Thread # " + (i + 1) + " is Opening \n"; textBoxList.SelectionStart = textBoxList.Text.Length; textBoxList.Text += Link + "\n"; textBoxList.SelectionLength = Link.Length; textBoxList.SelectionColor = Color.Blue; } while (Thread_Lock) { Thread.SpinWait(1000); } ChangeSubItem(i, 2, Link); ChangeSubItem(i, 1, "30%"); while (Thread_Lock) { Thread.SpinWait(1000); } //Critical Section-- worker can be replaced by another thread try { lock (worker = new ScrapingWorker(textBoxOutputFileName.Text, Link)) { worker.Maine(); } } catch (Exception w) { MessageBox.Show("CanNot Resolve URL, Maybe Server is down or Connection Time out\n\bMore Details\b\n " + w.Message); } while (Thread_Lock) { Thread.SpinWait(100); } ChangeSubItem(i, 1, "70%"); } }