Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with the CLR Thread Pool *****\n");
            Console.WriteLine("Main thread started. ThreadID = {0}", Thread.CurrentThread.ManagedThreadId);
            PrinterClass[] p        = new PrinterClass[10];
            WaitCallback   workItem = new WaitCallback(PrintTheNumbers);

            // Queue the method ten times.
            for (int i = 0; i < 10; i++)
            {
                p[i]      = new PrinterClass();
                p[i].name = string.Format("{0}", i);
                ThreadPool.QueueUserWorkItem(workItem, p[i]);
            }
            Console.WriteLine("All tasks queued");
            Console.ReadLine();
        }
Esempio n. 2
0
        static void PrintTheNumbers(object state)
        {
            PrinterClass task = (PrinterClass)state;

            task.PrintNumbers();
        }