多线程并发测试
2011-07-04 10:51 yuejianjun 阅读(297) 评论(0) 编辑 收藏 举报namespace Qunar
{
class Program
{
static void Main(string[] args)
{
int threadNum = 50;
//声明一个线程数组:并启动
Thread[] threads = new Thread[threadNum];
for (int i = 0; i < threadNum; i++)
{
threads[i] = new Thread(new ThreadStart(getdata));
threads[i].Name = (i + 1).ToString();
threads[i].IsBackground = true;
//启动
threads[i].Start();
}
Console.Read();
}
private static void getdata()
{
string[] a ={ "s", "sha", "上海", "b", "j", "t", "q", "l", "w", "p", "o", "v", "c", "北", "x", "m", "n", "z", "e", "r", "s", "sha", "上海", "b", "j", "t", "q", "l", "w", "p", "o", "v", "c", "北", "x", "m", "n", "z", "e", "r", "s", "sha", "上海", "b", "j", "t", "q", "l", "w", "p", "o", "v", "c", "北", "x", "m", "n", "z", "e", "r", };
int strID = Convert.ToInt32(Thread.CurrentThread.Name);
string str =a[strID ];
str = "http://localhost:5602/SearchTipJson.ashx?para=" + str + "&datetime=" + DateTime.Now.Millisecond.ToString() + (strID % 2 == 0 ? "s" : "h");
HttpClient H = new HttpClient();
str= H.GetHttpPage(str);
Console.WriteLine(str );
H.GetWriterHTML(@"D:\DownLoadPage\dianping\" + Thread.CurrentThread.Name + a[strID] + ".txt", str);
}
}
}
{
class Program
{
static void Main(string[] args)
{
int threadNum = 50;
//声明一个线程数组:并启动
Thread[] threads = new Thread[threadNum];
for (int i = 0; i < threadNum; i++)
{
threads[i] = new Thread(new ThreadStart(getdata));
threads[i].Name = (i + 1).ToString();
threads[i].IsBackground = true;
//启动
threads[i].Start();
}
Console.Read();
}
private static void getdata()
{
string[] a ={ "s", "sha", "上海", "b", "j", "t", "q", "l", "w", "p", "o", "v", "c", "北", "x", "m", "n", "z", "e", "r", "s", "sha", "上海", "b", "j", "t", "q", "l", "w", "p", "o", "v", "c", "北", "x", "m", "n", "z", "e", "r", "s", "sha", "上海", "b", "j", "t", "q", "l", "w", "p", "o", "v", "c", "北", "x", "m", "n", "z", "e", "r", };
int strID = Convert.ToInt32(Thread.CurrentThread.Name);
string str =a[strID ];
str = "http://localhost:5602/SearchTipJson.ashx?para=" + str + "&datetime=" + DateTime.Now.Millisecond.ToString() + (strID % 2 == 0 ? "s" : "h");
HttpClient H = new HttpClient();
str= H.GetHttpPage(str);
Console.WriteLine(str );
H.GetWriterHTML(@"D:\DownLoadPage\dianping\" + Thread.CurrentThread.Name + a[strID] + ".txt", str);
}
}
}