Class ThreadPool
Thread pool for scheduling sub-millisecond actions, do not schedule long-running tasks. Can be instantiated and generates less garbage than dotnet's.
public sealed class ThreadPool : IDisposable
- Inheritance
-
ThreadPool
- Implements
- Extension Methods
Constructors
ThreadPool(int?)
public ThreadPool(int? threadCount = null)
Parameters
threadCount
int?
Fields
Instance
The default instance that the whole process shares, use this one to avoid wasting process memory.
public static ThreadPool Instance
Field Value
WorkerThreadsCount
Amount of threads within this pool
public readonly int WorkerThreadsCount
Field Value
Properties
CompletedWork
Amount of work completed
public ulong CompletedWork { get; }
Property Value
IsWorkedThread
Is the thread reading this property a worker thread
public static bool IsWorkedThread { get; }
Property Value
ThreadsBusy
Amount of threads currently executing work items
public int ThreadsBusy { get; }
Property Value
WorkScheduled
Amount of work waiting to be taken care of
public int WorkScheduled { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
QueueUnsafeWorkItem(object, delegate*<object, void>, int)
Queue some work item to run on one of the available threads, it is strongly recommended that the action takes less than a millisecond. Additionally, the parameter provided must be fixed from this call onward until the action has finished executing
public void QueueUnsafeWorkItem(object parameter, delegate*<object, void> obj, int amount = 1)
Parameters
QueueWorkItem(Action, int)
Queue an action to run on one of the available threads, it is strongly recommended that the action takes less than a millisecond.
public void QueueWorkItem(Action workItem, int amount = 1)
Parameters
TryCooperate()
Attempt to steal work from the threadpool to execute it from the calling thread. If you absolutely have to block inside one of the threadpool's thread for whatever reason do a busy loop over this function.
public bool TryCooperate()