多线程webBrowser不起作用

我正在尝试编写多线程
WebBrowser
应用程序。
WebBrowser
元素将导航到给定的URL, 等到它加载然后 单击按钮或 提交表格。 这应该永远发生在循环中。 我正在使用Microsoft Visual Studio 2010和Windows窗体 这是我的代码:
//added windows form 30 webbrowser object 
//and now assigning them to an webbrowser array

wbList[0] = webBrowser1; wbList[1] = webBrowser2; wbList[2] = webBrowser3; 
wbList[3] = webBrowser4; wbList[4] = webBrowser5; wbList[5] = webBrowser6; 
wbList[6] = webBrowser7; wbList[7] = webBrowser8; wbList[8] = webBrowser9;
//etc. until:
wbList[29] = webBrowser30;

for (int i = 0; i < 30; i++)
{
    wbList[i].ScriptErrorsSuppressed = true;
    wbList[i].NewWindow += new CancelEventHandler(wb_NewWindow);
}

//********************************** creating threads here

Thread[] AllThread = new Thread[100];

int irWhichWbb = 0;
for (int nn = irDirectPostCount; nn < irNumber+1; nn++)
{
    AllThread[nn] = new Thread(new 
                          ParameterizedThreadStart(this.MultiThreadWebBrowser));
    AllThread[nn].Start(nn.ToString() + ";" + irWhichWbb.ToString());
    irWhichWbb++;
}

Application.DoEvents();
for (int nn = 0; nn < irNumber+1; nn++)
{ AllThread[nn].Join(); }
//Multi thread function
void MultiThreadWebBrowser(object parameter)
{
    string srParam = parameter.ToString();

    int i = Convert.ToInt32 (srParam.Substring(0,(srParam.IndexOf(";"))));
    int irWhichWb = Convert.ToInt32(srParam.Substring(srParam.IndexOf(";")+1));

    string hdrs = "Referer: http://www.xxxxxxxxx.com/xxxxxxxxxx.aspx";

    try
    {
        wbList[irWhichWb].Navigate(srVotingList[i, 0], "_self", null, hdrs);
    }
    catch { }

    try { waitTillLoad(irWhichWb); }
    catch { }
    waitTillLoad3();
}
// wait until webbrowser navigate url loaded
private void waitTillLoad(int irWhichLoad)
{
    WebBrowserReadyState loadStatus;
    //wait till beginning of loading next page  
    int waittime = 100000;
    int counter = 0;
    while (true)
    {
        try
        {
            loadStatus = wbList[irWhichLoad].ReadyState;
            Application.DoEvents();

            if ((counter > waittime) || 
                (loadStatus == WebBrowserReadyState.Uninitialized) || 
                (loadStatus == WebBrowserReadyState.Loading) || 
                (loadStatus == WebBrowserReadyState.Interactive))
            {
                    break;
            }
            counter++;
        }
        catch { }
    }

    //wait till the page get loaded.
    counter = 0;
    while (true)
    {
        try
        {
            loadStatus = wbList[irWhichLoad].ReadyState;
            Application.DoEvents();
            if (loadStatus == WebBrowserReadyState.Complete)
            {
                break;
            }
            if (counter > 10000000)
                break;
            counter++;
        }
        catch { }
    }
}
private void waitTillLoad3()
{
    DateTime dtStart = DateTime.Now;
    while (true)
    {
        if ((DateTime.Now - dtStart).TotalMilliseconds > 4000)
            break;

        Application.DoEvents();
    }
}
    
已邀请:
你没有说你得到了什么样的失败:“不起作用”并不是一个好的描述。 我首先尝试只使用一个线程。那样有用吗? 你有空的catch块,所以你默默地忽略了一些错误条件。这可能是隐藏一个问题。     

要回复问题请先登录注册