现在的位置: 首页 > 综合 > 正文

c# ThreadPool 应用实例

2019年01月12日 ⁄ 综合 ⁄ 共 461字 ⁄ 字号 评论关闭
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);
            }
           
            //
        }
    }
}

抱歉!评论已关闭.