private void MyThreadCalc(object Param) { ThreadParam tp = (ThreadParam)Param; String[] files = tp.files; foreach (String s in files) { Parser p = new Parser(s, errwr, outwr, writeOnlyCheck.Checked, DelimiterCheck.Checked, StaticCheck.Checked, TileCheck.Checked); BlockFile b = p.Parse(); lock (f.blockfileslist) { if (numBlocks.Value > 0 && f.blockfileslist.Count >= numBlocks.Value) { stopcollect = true; if (parseOnly.Checked) break; } if (!stopcollect) f.blockfileslist.Add(b); } if (closed) break; progressBar1.BeginInvoke(new IncDelegate(Inc)); } }
private void button2_Click(object sender, EventArgs e) { handle_select = false; this.blockbox.Text = ""; blocklist.DataSource = null; bool genera = extendedCheck.Checked; stopcollect = false; groupBox1.Enabled = false; groupBox2.Enabled = false; f=new Facet(); blocklist.DataSource = null; GC.Collect(); String[] files = Directory.GetFiles(textBox2.Text, "*.dat"); IComparer icomp = new FileComparer(); Array.Sort(files, icomp); progressBar1.Minimum = 0; progressBar1.Maximum = (parseOnly.Checked && numBlocks.Value>0) ? (int)numBlocks.Value : files.Length; progressBar1.Value = 0; errwr = new StreamWriter("error.log"); outwr = null; if(genera) outwr = new StreamWriter("outuput.log"); int div = (parseOnly.Checked && numBlocks.Value > 0) ? (int)numBlocks.Value : files.Length / 3; if (div > 50) { bw1.RunWorkerAsync(files); } else { foreach (String s in files) { Parser p = new Parser(s, errwr, outwr, writeOnlyCheck.Checked, DelimiterCheck.Checked, StaticCheck.Checked, TileCheck.Checked); BlockFile b = p.Parse(); if (numBlocks.Value > 0 && f.blockfileslist.Count >= numBlocks.Value) { stopcollect = true; if (parseOnly.Checked) break; } if (!stopcollect) { f.blockfiles.AddLast(b); f.blockfileslist.Add(b); } Inc(); if (closed) break; } bw1_RunWorkerCompleted(null, null); } }