ThreadPool.QueueUserWorkItem : Thread Pool « Thread « C# / C Sharp






ThreadPool.QueueUserWorkItem

 


using System;
using System.Threading;


class WinterLocked {
    public ManualResetEvent a = new ManualResetEvent(false);
    private int i = 5;

    public void Run(object s) {
        Interlocked.Increment(ref i);
        Console.WriteLine("{0} {1}",
                          Thread.CurrentThread.GetHashCode(), i);
    }
}

public class MainApp {
    public static void Main() {
        ManualResetEvent mR = new ManualResetEvent(false);
        WinterLocked wL = new WinterLocked();
        for (int i = 1; i <= 10; i++) {
            ThreadPool.QueueUserWorkItem(new WaitCallback(wL.Run), 1);
        }
        mR.WaitOne(10000, true);
    }
}
  

 








Related examples in the same category

1.ThreadPool.RegisterWaitForSingleObject
2.Thread pool demoThread pool demo
3.illustrates the use of the system thread poolillustrates the use of the system thread pool
4.Thread Pool Tcp Server
5.Thread Pool SampleThread Pool Sample