线程池的使用

static void Main(string[] args)
{
//写日志
//使用线程池
for (int i = 0; i < 1000; i++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(ReceiveMessage), i);
}

Console.ReadKey();
}

private static void ReceiveMessage(object index)
{
Thread.Sleep(100);
int b = 0;
try
{
if (index.ToString() == "50")
{
Console.WriteLine(100 / b);
}
else
{
Console.WriteLine(index.ToString());
}
}
catch (Exception)
{
Console.WriteLine(index+":出错");
}


}

posted @ 2019-04-28 13:49  厦门哈韩  阅读(100)  评论(0编辑  收藏  举报