Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.55 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why does this C# ThreadPool sometimes drop work items?
  2. class Program
  3. {
  4.     private int x = 0;
  5.     static void Main(string[] args)
  6.     {
  7.  
  8.         Program p = new Program();
  9.         int a, b;
  10.         ThreadPool.GetMaxThreads(out a, out b);
  11.         Console.WriteLine("{0} - {1}", a, b);
  12.         for (int y = 0; y < 20; y++)
  13.         {
  14.             WaitCallback cb = new WaitCallback(DoSomething);
  15.  
  16.             ThreadPool.QueueUserWorkItem(cb, y);
  17.         }
  18.     }
  19.  
  20.     public static void DoSomething(object state)
  21.     {
  22.         Console.WriteLine(state);
  23.     }
  24. }