线程池

public class QueueUseWorkItem{
    public static void Run(){
        Stopwatch watch = Stopwatch.StartNew();
        watch.Start();
        WaitCallback callback = index =>{
            System.Console.WriteLine($"在{watch.Elapsed}毫秒,线程{index}启动成功");
        };

        for(int i=0; i<20; i++)
        {
            ThreadPool.QueueUserWorkItem(callback,i);
        }
    }

}

 

posted @ 2023-11-28 07:22  vba是最好的语言  阅读(11)  评论(0编辑  收藏  举报