您的位置:首页 > 编程语言 > C#

c# ThreadPool 应用实例

2014-11-21 00:51 225 查看
namespace ThreadPoolTestCase
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 10000; i++)
{
int state = i;
AssignWork(state);
Console.WriteLine(i);
}
Console.ReadKey();
}

public static void AssignWork(object s)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), (object)s);
Console.WriteLine(s);
//wait.Reset();

}
private static void DoWork(object o)
{//may be smtp works here;
Console.WriteLine("abcdef");
for (int i = 0; i < 100000; i++)
{
Console.WriteLine("abcdef");
Thread.Sleep(1000);
}

//
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: