【发布时间】:2012-02-09 12:48:12
【问题描述】:
我想通过多重访问来强调我的网站。为此,我创建了一个基于 Windows 的应用程序,该应用程序调用网站的 1000 次。 不幸的是,它只适用于 2 次通话。这是代码:
static void myMethod( int i)
{
int j = 0;
try
{
string url = "";
WebRequest wr = null;
HttpWebResponse response = null;
url = String.Format("http://www.google.com");
wr = WebRequest.Create(url);
//wr.Timeout = 1000;
response = (HttpWebResponse)wr.GetResponse();
MessageBox.Show("end");
}
catch (Exception ex)
{
MessageBox.Show(j.ToString() + " " + ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 1000; i++)
{
ThreadStart starter = delegate { myMethod(i); };
Thread thread = new Thread(starter);
thread.Start();
}
}
【问题讨论】:
-
两次尝试后会发生什么?有没有抛出异常?
-
你知道,如果这行得通,你会产生 1000 个消息框,对吧?另外-我不确定您是否可以从后台线程打开消息框。谁能证实这一点?
-
为什么要尝试重新发明已经可用的东西。 support.microsoft.com/kb/231282loadimpact.com
标签: c# asp.net multithreading stress-testing