private void ParseButton_Click(object sender, EventArgs e) { switch (ParseButton.Text) { case "Parse": CsvReaderWriter crw = new CsvReaderWriter(FilePath_textBox.Text, requester.GetResultPath()); parsing_progressBar.Value = 0; parsing_progressBar.Maximum = crw.getMax(); for (int i = 0; i < Streams_numericUpDown.Value; i++) { Thread t = new Thread(delegate () { while (true) { string source; lock (crw) { source = crw.getNextSource(); } if (source == null) { MessageBox.Show("Done!"); break; } ParsedResult parsedResult = requester.Parse(source); Progress_Label.Invoke(new Action(() => { parsing_progressBar.Value++; Progress_Label.Text = parsing_progressBar.Value.ToString() + "/" + parsing_progressBar.Maximum.ToString(); TimeLeft_label.Text = getLeftTime(); })); lock (crw) { crw.insertParsed(parsedResult); } Thread.Sleep((int)Time_Out_numericUpDown.Value * 1000); } }); t.Start(); threads.Add(t); } break; case "Pause": foreach (var item in threads) { if (item.IsAlive) item. } break; case "Continue": break; default: break; } }
private void ParseButton_Click(object sender, EventArgs e) { switch (ParseButton.Text) { case "Start": bool write_headers = true; if (radioButton3.Checked) { if ((!Da_pa_checkbox.Checked && !Cf_tf_checkbox.Checked)) { MessageBox.Show("Выберете хоть одну метрику!"); return; } write_headers = false; } isparsedtoken = true; crw = new CsvReaderWriter(ParseFilePath_textBox.Text, parserequester.GetResultPath(), Da_pa_checkbox.Checked, Cf_tf_checkbox.Checked, write_headers, false); parsing_progressBar.Value = 0; parsing_progressBar.Maximum = crw.getMax(); for (int i = 0; i < Streams_numericUpDown.Value; i++) { Thread t = new Thread(delegate() { while (true) { if (isparsedtoken) { string source; lock (crw) { source = crw.getNextSource(); } if (source == null) { CancelButton.Invoke(new Action(() => { ParseButton.Text = "Start"; isparsedtoken = false; })); break; } ParsedResult parsedResult = parserequester.Parse(source); if (Da_pa_checkbox.Checked || Cf_tf_checkbox.Checked) { parserequester.getDA_PA(source, parsedResult); } Progress_Label.Invoke(new Action(() => { parsing_progressBar.Value++; Progress_Label.Text = parsing_progressBar.Value.ToString() + "/" + parsing_progressBar.Maximum.ToString(); TimeLeft_label.Text = getLeftTime((int)Time_Out_numericUpDown.Value, (int)Streams_numericUpDown.Value); })); Thread.Sleep((int)Time_Out_numericUpDown.Value * 1000); lock (crw) { crw.insertParsed(parsedResult); } } } }); t.Start(); threads.Add(t); } ParseButton.Text = "Pause"; CancelButton.Enabled = true; break; case "Pause": isparsedtoken = false; ParseButton.Text = "Continue"; break; case "Continue": isparsedtoken = true; ParseButton.Text = "Pause"; break; default: break; } }
private void Whoisstart_button_Click_1(object sender, EventArgs e) { switch (WhoisStart_button.Text) { case "Start": iswhoistoken = true; whoisreader = new CsvReaderWriter(Whois_textBox.Text, whoisrequester.GetResultPath(), false, false, false, true); Whois_progressBar.Value = 0; Whois_progressBar.Maximum = whoisreader.getMax(); for (int i = 0; i < WhoisStreams_numericUpDown.Value; i++) { Thread t = new Thread(delegate() { while (true) { if (iswhoistoken) { string source; lock (whoisreader) { source = whoisreader.getNextSource(); } if (source == null) { WhoisCancel_button.Invoke(new Action(() => { WhoisStart_button.Text = "Start"; iswhoistoken = false; WhoisCancel_button.Enabled = false; })); break; } ParsedResult parsedResult = whoisrequester.Parse(source); WhoisCountLeft_label.Invoke(new Action(() => { Whois_progressBar.Value++; WhoisCountLeft_label.Text = Whois_progressBar.Value.ToString() + "/" + Whois_progressBar.Maximum.ToString(); WhoisTimeLeft_label.Text = getWhoisLeftTime((int)Whois_TimeOut_numericUpDown.Value, (int)WhoisStreams_numericUpDown.Value); })); Thread.Sleep((int)Whois_TimeOut_numericUpDown.Value * 1000); lock (whoisreader) { whoisreader.insertParsed(parsedResult); } } } }); t.Start(); threads.Add(t); } WhoisStart_button.Text = "Pause"; WhoisCancel_button.Enabled = true; break; case "Pause": iswhoistoken = false; WhoisStart_button.Text = "Continue"; break; case "Continue": iswhoistoken = true; WhoisStart_button.Text = "Pause"; break; default: break; } }