new WaitCallback : WaitCallback « Thread « C# / C Sharp






new WaitCallback

 
using System;
using System.Threading;

class ThreadPoolDemo {
    public void LongTask1(object obj) {
        for (int i = 0; i <= 999; i++) {
            Console.WriteLine("Long Task 1 is being executed");
        }
    }
    public void LongTask2(object obj) {
        for (int i = 0; i <= 999; i++) {
            Console.WriteLine("Long Task 2 is being executed");
        }
    }

    static void Main() {
        ThreadPoolDemo tpd = new ThreadPoolDemo();
        for (int i = 0; i < 50; i++) {
            ThreadPool.QueueUserWorkItem(new WaitCallback(tpd.LongTask1));
            ThreadPool.QueueUserWorkItem(new WaitCallback(tpd.LongTask2));
        }

        Console.Read();
    }
}

 








Related examples in the same category