private void GetLinksAuto(object sender, DoWorkEventArgs e) { List<string> s = new List<string>(); //string[] s = new string[checkedListBox1.Items.Count]; for (int i = 0; i < checkedListBox1.Items.Count; i++) if ((DateTime.Now - dict[(string)checkedListBox1.Items[i]].lastdate).TotalHours >24) s.Add((string)checkedListBox1.Items[i]); ParallelOptions po = new ParallelOptions(); po.MaxDegreeOfParallelism = 5; Parallel.For(0, s.Count(), po, i => //Parallel.ForEach(s, po, i => { if(auto) try { job_with_form j = new job_with_form(dict[s[i]], s[i]); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += j.MakeJob; //bw.RunWorkerAsync(); bw.RunWorkerAsync(); j.ShowDialog(); } catch (Exception ex) { ddbs.WriteErrorMessage(ddbs.ConnectionString, 0, null, "Ошибка парсинга ссылок: " + ex.Message); } }); renameButt5(); }
private void GetLinks(object sender, DoWorkEventArgs e) { string[] s = new string[checkedListBox1.CheckedItems.Count]; for (int i = 0; i < s.Count(); i++) s[i] = (string)checkedListBox1.CheckedItems[i]; Parallel.ForEach(s, i => { try { job_with_form j = new job_with_form(dict[i], i); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += j.MakeJob; //bw.RunWorkerAsync(); bw.RunWorkerAsync(); j.ShowDialog(); } catch (Exception ex) { ddbs.WriteErrorMessage(ddbs.ConnectionString, 0, null, "Ошибка парсинга ссылок: " + ex.Message); } }); }