ThreadPool.QueueUserWorkItem : Thread Pool : Thread C# Source Code


Custom Search

C# Source Code » Thread » Thread Pool »

 

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);
    }
}
  

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Thread
» Thread Pool