这是Form1
public static BackgroundWorker[] threadArray;
//public static AutoResetEvent[] _eventHandles ;
public static readonly object _lockObj = new object();
public static bool _go ;
//public static ManualResetEvent _manualResetEvent = new ManualResetEvent(false);
private void BackgroundWorkerFilesDoWork(object sender, DoWorkEventArgs e)
{
...
lock (_lockObj)
{
//_manualResetEvent.WaitOne(30000);
//_manualResetEvent.Reset();
//if (clsValueStatic.CaptchaText != null)
//{
// foreach (var id in clsValueStatic.CaptchaText)
// {
while (!_go)
{
Monitor.Wait(_lockObj);
}
// }
//}
}
...
}
private void btn_Start_Scraping_Click(object sender, EventArgs e)
{
ServicePointManager.DefaultConnectionLimit = slider_Thread.Value;
threadArray = new BackgroundWorker[listView_Site.Items.Count];
for (var f = 0; f < listView_Site.Items.Count; f++)
{
threadArray[f] = new BackgroundWorker();
threadArray[f].DoWork += new DoWorkEventHandler(BackgroundWorkerFilesDoWork);
threadArray[f].RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorkerFilesRunWorkerCompleted);
threadArray[f].ProgressChanged += new ProgressChangedEventHandler(BackgroundWorkerFilesProgressChanged);
threadArray[f].WorkerReportsProgress = true;
threadArray[f].WorkerSupportsCancellation = true;
threadArray[f].RunWorkerAsync(listView_Site.Items[f].Tag.ToString());
}
}
这是Form2
private void textBoxCaptcha_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
var textBox = sender as TextBoxX;
if (textBox != null)
{
lock (frmScrapingAnalysis._lockObj)
{
//clsValueStatic.CaptchaText = null;
////frmScrapingAnalysis._go = true;
//clsValueStatic.CaptchaText.Add(textBox.Tag.ToString(), textBox.Text.Trim());
//textBox.Parent.Parent.Dispose();
Monitor.Pulse(frmScrapingAnalysis._lockObj);
}
//frmScrapingAnalysis._manualResetEvent.Set();
//frmScrapingAnalysis._eventHandles[frmScrapingAnalysis.positionThread].Set();
}
}
}
这是登录网站的程序