2 // System.Threading.ThreadPool
6 // Dick Porter (dick@ximian.com)
7 // Maurer Dietmar (dietmar@ximian.com)
9 // (C) Ximian, Inc. http://www.ximian.com
12 using System.Collections;
13 using System.Runtime.CompilerServices;
15 namespace System.Threading {
17 public sealed class ThreadPool {
24 public static bool BindHandle (IntPtr osHandle)
26 throw new NotSupportedException("This is MS specific");
29 [MethodImplAttribute(MethodImplOptions.InternalCall)]
30 public static extern void GetAvailableThreads (out int workerThreads, out int completionPortThreads);
32 [MethodImplAttribute(MethodImplOptions.InternalCall)]
33 public static extern void GetMaxThreads (out int workerThreads, out int completionPortThreads);
35 public static bool QueueUserWorkItem (WaitCallback callback)
37 IAsyncResult ar = callback.BeginInvoke (null, null, null);
43 public static bool QueueUserWorkItem (WaitCallback callback, object state)
45 IAsyncResult ar = callback.BeginInvoke (state, null, null);
51 public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
52 WaitOrTimerCallback callBack,
54 int millisecondsTimeOutInterval,
57 return RegisterWaitForSingleObject (waitObject, callBack, state,
58 (long) millisecondsTimeOutInterval, executeOnlyOnce);
61 public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
62 WaitOrTimerCallback callBack,
64 long millisecondsTimeOutInterval,
67 if (millisecondsTimeOutInterval < -1)
68 throw new ArgumentOutOfRangeException ("timeout", "timeout < -1");
70 if (millisecondsTimeOutInterval > Int32.MaxValue)
71 throw new NotSupportedException ("Timeout is too big. Maximum is Int32.MaxValue");
73 TimeSpan timeout = new TimeSpan (0, 0, 0, 0, (int) millisecondsTimeOutInterval);
75 RegisteredWaitHandle waiter = new RegisteredWaitHandle (waitObject, callBack, state,
76 timeout, executeOnlyOnce);
77 QueueUserWorkItem (new WaitCallback (waiter.Wait), null);
81 public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
82 WaitOrTimerCallback callBack,
87 return RegisterWaitForSingleObject (waitObject, callBack, state,
88 (long) timeout.TotalMilliseconds, executeOnlyOnce);
93 public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
94 WaitOrTimerCallback callBack,
96 uint millisecondsTimeOutInterval,
99 return RegisterWaitForSingleObject (waitObject, callBack, state,
100 (long) millisecondsTimeOutInterval, executeOnlyOnce);
103 public static bool UnsafeQueueUserWorkItem (WaitCallback callback, object state)
105 IAsyncResult ar = callback.BeginInvoke (state, null, null);