private void Crawler_FormClosing(object sender, FormClosingEventArgs e) { ThreadStop = true; ToggleRunningButton.Text = "Stopping..."; ToggleRunningButton.Update(); Crawler.ActiveForm.Enabled = false; Crawler.ActiveForm.UseWaitCursor = true; Crawler.ActiveForm.Update(); }
private void ToggleRunningButton_Click(object sender, EventArgs e) { ToggleRunningButton.Enabled = false; if (ThreadStop) { ToggleRunningButton.Text = "Starting..."; ToggleRunningButton.UseWaitCursor = true; ToggleRunningButton.Update(); while (ThreadRunning == true) { Thread.Sleep(100); } string orderbyString = ""; switch (SelectorBox.SelectedIndex) { case 0: orderbyString = "latest"; break; case 1: orderbyString = "downloads"; break; case 2: orderbyString = "hot"; break; default: ToggleRunningButton.Text = "Start"; ToggleRunningButton.Update(); return; } ThreadStop = false; ThreadRunning = true; SelectorBox.Enabled = false; Task.Run(() => { MainLoop(orderbyString); ThreadRunning = false; }).ConfigureAwait(false); ToggleRunningButton.Text = "Stop"; } else { ToggleRunningButton.Text = "Stopping..."; ToggleRunningButton.UseWaitCursor = false; ToggleRunningButton.Update(); ThreadStop = true; while (ThreadRunning == true) { Thread.Sleep(100); } SelectorBox.Enabled = true; ToggleRunningButton.Text = "Start"; } ToggleRunningButton.Enabled = true; }