Class Dispatcher
public static class Dispatcher
- Inheritance
-
objectDispatcher
Properties
MaxDegreeOfParallelism
public static int MaxDegreeOfParallelism { get; set; }
Property Value
Methods
ForBatched<TJob>(int, TJob)
The call producing the least amount of overhead, other methods are built on top of this one.
public static void ForBatched<TJob>(int items, TJob batchJob) where TJob : Dispatcher.IBatchJob
Parameters
itemsintThe amount of items to process, this total will be split into multiple batches, each batch runs
TJob.Process(int, int) with the range of items for that batchbatchJobTJobAn object shared across all threads running this job, if TJob is a struct each threads will work off of a unique copy of it
Type Parameters
TJob
Exceptions
- Exception
A batch threw: no new batch starts, and the first exception is rethrown in the caller's scope once the running batches end.
ForBatched<TState>(int, TState, Action<TState, int, int>)
Splits items into batches and runs executeBatch on each batch, on multiple threads.
public static void ForBatched<TState>(int items, TState state, Action<TState, int, int> executeBatch)
Parameters
itemsintThe number of items to process.
stateTStateThe value passed to each
executeBatchcall.executeBatchAction<TState, int, int>Called with the state and the range of a batch, from inclusive to exclusive.
Type Parameters
TState
Remarks
Use a static lambda and pass what it needs through state, so that the call does not allocate.
ForBatched<T>(int, ref T, delegate*<ref T, int, int, void>)
public static void ForBatched<T>(int items, ref T parameter, delegate*<ref T, int, int, void> executeBatch)
Parameters
Type Parameters
T
ForBatched<T>(int, ref T, delegate*<ref T, int, int, void>)
public static void ForBatched<T>(int items, ref T parameter, delegate*<ref T, int, int, void> executeBatch)
Parameters
Type Parameters
T
ForEach<T, TState>(IReadOnlyList<T>, TState, Action<TState, T>)
Runs action for each item of collection, on multiple threads.
public static void ForEach<T, TState>(IReadOnlyList<T> collection, TState state, Action<TState, T> action)
Parameters
collectionIReadOnlyList<T>The items to process.
stateTStateThe value passed to each
actioncall.actionAction<TState, T>Called with the state and the item.
Type Parameters
TTState
Remarks
Use a static lambda and pass what it needs through state, so that the call does not allocate.
For<TState>(int, int, TState, Action<TState, int>)
Runs action for each index from fromInclusive to toExclusive, on multiple threads.
public static void For<TState>(int fromInclusive, int toExclusive, TState state, Action<TState, int> action)
Parameters
fromInclusiveintThe first index.
toExclusiveintThe index after the last one.
stateTStateThe value passed to each
actioncall.actionAction<TState, int>Called with the state and the index.
Type Parameters
TState
Remarks
Use a static lambda and pass what it needs through state, so that the call does not allocate.
Sort<T>(FastList<T>, IComparer<T>)
[Obsolete("This method will be removed in the future alongside FastList. We will have an alternative using Span<T> which you will be able to fallback to.")]
public static void Sort<T>(FastList<T> collection, IComparer<T> comparer)
Parameters
Type Parameters
T
Sort<T>(ConcurrentCollector<T>, IComparer<T>)
public static void Sort<T>(ConcurrentCollector<T> collection, IComparer<T> comparer)
Parameters
collectionConcurrentCollector<T>comparerIComparer<T>
Type Parameters
T
Sort<T>(T[], int, int, IComparer<T>)
Sorts a range of collection, splitting a range of more than 2,048 items between threads.
public static void Sort<T>(T[] collection, int index, int length, IComparer<T> comparer)
Parameters
Type Parameters
T
Exceptions
- InvalidOperationException
comparerthrew inside Sort<T>(T[], int, int, IComparer<T>), which sorts every range of at most 2,048 items; the comparer's exception is the inner exception.- Exception
comparerthrew while a larger range was split; it is rethrown once the other threads have stopped.
Events
OnMaxDegreeOfParallelismChanged
public static event Action? OnMaxDegreeOfParallelismChanged