public string HttpGet(string URI) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URI); req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; req.Accept = "*/*"; req.Headers.Add("UA-CPU", "x86"); req.Headers.Add("Accept-Language", "en-us"); req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)"; HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); //Read all headers from the response & Request WebHeaderCollection ResponseHeader = resp.Headers; WebHeaderCollection RequestHeader = req.Headers; StreamReader sr = new StreamReader(resp.GetResponseStream()); string s = URI; string s1 = req.RequestUri + " / " + (int)resp.StatusCode + " / " + resp.StatusDescription + Environment.NewLine + ResponseHeader.ToString() + sr.ReadToEnd(); string s2 = req.RequestUri + " /" + req.Method + " / " + req.ProtocolVersion + " / " + Environment.NewLine + RequestHeader.ToString(); NetworkMonitor(s, s1, s2); return s1.Trim(); } private void bw_DoWork(object sender, DoWorkEventArgs e) { // startextraction(); BackgroundWorker worker = (BackgroundWorker)sender; try { using (StreamReader reader = new StreamReader("F://testing.txt")) { int out_count = 0; int out_count_1 = 0; int out_count_2 = 0; int row_count = 0; DataTable table = new DataTable(); foreach (DataRow rw in table_1.Rows) { table.Columns.Add(rw[0].ToString()); } string input; int i = 0; while ((input = reader.ReadLine()) != null) { string sourcecode = HttpGet(input); worker.ReportProgress(i); //string sourcecode = HttpPost(input, PostRaw); //run_logs.AppendText("[Traversed] " + input + DateTime.Now.ToString()); //run_logs.AppendText(Environment.NewLine); //run_logs.Update(); // Here we check the Match instance. foreach (DataRow row in table_1.Rows) { int index = table_1.Rows.IndexOf(row); //Here we call Regex.Match. Match match = Regex.Match(sourcecode, row[1].ToString(), RegexOptions.IgnoreCase); int count = 0; while (match.Success) { // Finally, we get the Group value and display it. if (index == 0) { table.Rows.Add(match.Groups[Convert.ToInt32(row[2].ToString())].Value); row_count++; } else if (index == 1) { try { table.Rows[out_count][index] = match.Groups[Convert.ToInt32(row[2].ToString())].Value; } catch { table.Rows.Add(); } finally { table.Rows[out_count][index] = match.Groups[Convert.ToInt32(row[2].ToString())].Value; } out_count++; } else if (index == 2) { try { table.Rows[out_count_1][index] = match.Groups[Convert.ToInt32(row[2].ToString())].Value; } catch { table.Rows.Add(); } finally { table.Rows[out_count_1][index] = match.Groups[Convert.ToInt32(row[2].ToString())].Value; } out_count_1++; } else if (index == 3) { try { table.Rows[out_count_2][index] = match.Groups[Convert.ToInt32(row[2].ToString())].Value; } catch { table.Rows.Add(); } finally { table.Rows[out_count_2][index] = match.Groups[Convert.ToInt32(row[2].ToString())].Value; } out_count_2++; } else { } count++; match = match.NextMatch(); } // run_logs.AppendText("[REGEX] " + regex + " Extracted " + count + " Matches"); // run_logs.AppendText(Environment.NewLine); } //toolStripProgressBar1.Maximum = 4; //toolStripProgressBar1.Value = toolStripProgressBar1.Value + 1; // run_logs.Update(); dataGridView1.DataSource = table; dataGridView1.Update(); dataGridView1.FirstDisplayedScrollingRowIndex = row_count; } } } catch (Exception hg) { MessageBox.Show(hg.Message); } }
Quote:the problem is Cross-thread operation not valid: Control 'dataGridView1' accessed from a thread other than the thread it was created on
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)