using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System.Threading
{
/// Provides a pool of threads that can be used to post work items, process asynchronous I/O, wait on behalf of other threads, and process timers.
/// 2
// Token: 0x02000621 RID: 1569
public static class ThreadPool
{
/// Binds an operating system handle to the .
/// true if the handle is bound; otherwise, false.
/// An that holds the handle. The handle must have been opened for overlapped I/O on the unmanaged side.
/// The caller does not have the required permission.
/// 1
// Token: 0x060039B8 RID: 14776 RVA: 0x000C62F8 File Offset: 0x000C44F8
[Obsolete("This method is obsolete, use BindHandle(SafeHandle) instead")]
public static bool BindHandle(IntPtr osHandle)
{
return true;
}
/// Binds an operating system handle to the .
/// true if the handle is bound; otherwise, false.
/// A that holds the operating system handle. The handle must have been opened for overlapped I/O on the unmanaged side.
///
/// is null.
// Token: 0x060039B9 RID: 14777 RVA: 0x000C62FC File Offset: 0x000C44FC
public static bool BindHandle(SafeHandle osHandle)
{
if (osHandle == null)
{
throw new ArgumentNullException("osHandle");
}
return true;
}
/// Retrieves the number of requests to the thread pool that can be active concurrently. All requests above that number remain queued until thread pool threads become available.
/// The maximum number of worker threads in the thread pool.
/// The maximum number of asynchronous I/O threads in the thread pool.
/// 1
// Token: 0x060039BA RID: 14778
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void GetMaxThreads(out int workerThreads, out int completionPortThreads);
/// Retrieves the number of idle threads the thread pool maintains in anticipation of new requests.
/// The minimum number of idle worker threads currently maintained by the thread pool.
/// The minimum number of idle asynchronous I/O threads currently maintained by the thread pool.
/// 1
// Token: 0x060039BB RID: 14779
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void GetMinThreads(out int workerThreads, out int completionPortThreads);
/// Sets the number of idle threads the thread pool maintains in anticipation of new requests.
/// true if the change is successful; otherwise, false.
/// The new minimum number of idle worker threads to be maintained by the thread pool.
/// The new minimum number of idle asynchronous I/O threads to be maintained by the thread pool.
/// 1
///
///
///
// Token: 0x060039BC RID: 14780
[MonoTODO("The min number of completion port threads is not evaluated.")]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool SetMinThreads(int workerThreads, int completionPortThreads);
/// Sets the number of requests to the thread pool that can be active concurrently. All requests above that number remain queued until thread pool threads become available.
/// true if the change is successful; otherwise, false.
/// The maximum number of worker threads in the thread pool.
/// The maximum number of asynchronous I/O threads in the thread pool.
/// 1
///
///
///
// Token: 0x060039BD RID: 14781
[MonoTODO("The max number of threads cannot be decremented.")]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool SetMaxThreads(int workerThreads, int completionPortThreads);
/// Queues a method for execution. The method executes when a thread pool thread becomes available.
/// true if the method is successfully queued; is thrown if the work item is not queued.
/// A that represents the method to be executed.
/// The common language runtime (CLR) is hosted, and the host does not support this action.
///
/// is null.
/// 1
// Token: 0x060039BE RID: 14782 RVA: 0x000C6310 File Offset: 0x000C4510
public static bool QueueUserWorkItem(WaitCallback callBack)
{
return ThreadPool.QueueUserWorkItem(callBack, null);
}
/// Queues a method for execution, and specifies an object containing data to be used by the method. The method executes when a thread pool thread becomes available.
/// true if the method is successfully queued; is thrown if the work item could not be queued.
/// A representing the method to execute.
/// An object containing data to be used by the method.
/// The common language runtime (CLR) is hosted, and the host does not support this action.
///
/// is null.
/// 1
// Token: 0x060039BF RID: 14783 RVA: 0x000C631C File Offset: 0x000C451C
public static bool QueueUserWorkItem(WaitCallback callBack, object state)
{
if (callBack == null)
{
throw new ArgumentNullException("callBack");
}
return callBack.BeginInvoke(state, null, null) != null;
}
/// Registers a delegate to wait for a , specifying a 32-bit signed integer for the time-out in milliseconds.
/// The that encapsulates the native handle.
/// The to register. Use a other than .
/// The delegate to call when the parameter is signaled.
/// The object that is passed to the delegate.
/// The time-out in milliseconds. If the parameter is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses.
/// true to indicate that the thread will no longer wait on the parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
/// The parameter is less than -1.
/// 1
// Token: 0x060039C0 RID: 14784 RVA: 0x000C6350 File Offset: 0x000C4550
public static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, int millisecondsTimeOutInterval, bool executeOnlyOnce)
{
return ThreadPool.RegisterWaitForSingleObject(waitObject, callBack, state, (long)millisecondsTimeOutInterval, executeOnlyOnce);
}
/// Registers a delegate to wait for a , specifying a 64-bit signed integer for the time-out in milliseconds.
/// The that encapsulates the native handle.
/// The to register. Use a other than .
/// The delegate to call when the parameter is signaled.
/// The object passed to the delegate.
/// The time-out in milliseconds. If the parameter is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses.
/// true to indicate that the thread will no longer wait on the parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
/// The parameter is less than -1.
/// 1
// Token: 0x060039C1 RID: 14785 RVA: 0x000C6360 File Offset: 0x000C4560
public static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval, bool executeOnlyOnce)
{
if (millisecondsTimeOutInterval < -1L)
{
throw new ArgumentOutOfRangeException("timeout", "timeout < -1");
}
if (millisecondsTimeOutInterval > 2147483647L)
{
throw new NotSupportedException("Timeout is too big. Maximum is Int32.MaxValue");
}
TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, (int)millisecondsTimeOutInterval);
RegisteredWaitHandle registeredWaitHandle = new RegisteredWaitHandle(waitObject, callBack, state, timeSpan, executeOnlyOnce);
ThreadPool.QueueUserWorkItem(new WaitCallback(registeredWaitHandle.Wait), null);
return registeredWaitHandle;
}
/// Registers a delegate to wait for a , specifying a value for the time-out.
/// The that encapsulates the native handle.
/// The to register. Use a other than .
/// The delegate to call when the parameter is signaled.
/// The object passed to the delegate.
/// The time-out represented by a . If is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses.
/// true to indicate that the thread will no longer wait on the parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
/// The parameter is less than -1.
/// The parameter is greater than .
/// 1
// Token: 0x060039C2 RID: 14786 RVA: 0x000C63CC File Offset: 0x000C45CC
public static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, TimeSpan timeout, bool executeOnlyOnce)
{
return ThreadPool.RegisterWaitForSingleObject(waitObject, callBack, state, (long)timeout.TotalMilliseconds, executeOnlyOnce);
}
/// Registers a delegate to wait for a , specifying a 32-bit unsigned integer for the time-out in milliseconds.
/// The that can be used to cancel the registered wait operation.
/// The to register. Use a other than .
/// The delegate to call when the parameter is signaled.
/// The object passed to the delegate.
/// The time-out in milliseconds. If the parameter is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses.
/// true to indicate that the thread will no longer wait on the parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
/// The parameter is less than -1.
/// 1
// Token: 0x060039C3 RID: 14787 RVA: 0x000C63E0 File Offset: 0x000C45E0
[CLSCompliant(false)]
public static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce)
{
return ThreadPool.RegisterWaitForSingleObject(waitObject, callBack, state, (long)((ulong)millisecondsTimeOutInterval), executeOnlyOnce);
}
}
}