使用线程同时运行6个浏览器 [英] Run 6 browser simultaneously using Threads
本文介绍了使用线程同时运行6个浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在SENuke这样的项目中同时运行6个浏览器.请告诉我我如何使用线程.所有浏览器都在运行,但是发生异常"InvalidCastException".请帮助我这样做.
Hi,
I want To run 6 browser simultaneously in my project like SENuke. Please tell me how i do using Threads. All browsers are running but there occurs exception "InvalidCastException". Please Help me to doing this.
private void btnSubmit_Click(object sender, EventArgs e)
{
Thread m_thread = new Thread(new ThreadStart(hotfrogs));
m_thread.SetApartmentState(ApartmentState.STA);
m_thread.Start();
Thread m_thread1 = new Thread(new ThreadStart(abc))
m_thread1.Start();
}
public void hotfrogs()
{
try
{
webBrowser1.Navigate("http://www.google.com");
webBrowser1.Document.Forms[0].GetElementsByTagName("input")["q"].SetAttribute("value", "C#.net");
webBrowser1.Document.Forms[0].GetElementsByTagName("input")["btnG"].InvokeMember("click");
}
catch(Exception)
{}
}
public void abc()
{
try
{
webBrowser2.Navigate("http://www.google.com");
webBrowser2.Document.Forms[0].GetElementsByTagName("input")["q"].SetAttribute("value", "Asp.net");
webBrowser2.Document.Forms[0].GetElementsByTagName("input")["btnG"].InvokeMember("click");
}
catch(Exception)
{}
}
推荐答案
您不需要在单独的线程中运行它们.只需创建六个浏览器窗口(您可以通过视觉方式对其进行管理即可),而Bob是您的叔叔.
You don''t need to run them in separate threads. Just create the six browser windows (how you visually manage them is up to you), and Bob''s your uncle.
这篇关于使用线程同时运行6个浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文