Class ThreadingExtensions
Convenience extensions for utilizing multiple threads and using the ThreadingHelper.
Syntax
public static class ThreadingExtensions
Methods
Apply a function to a collection of data by spreading the work on multiple threads. Outputs of the functions are returned to the current thread and yielded one by one.
Declaration
public static IEnumerable<TOut> RunParallel<TIn, TOut>(this IEnumerable<TIn> data, Func<TIn, TOut> work, int workerCount = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TIn> |
data |
|
System.Func<TIn, TOut> |
work |
Function to apply to the data on multiple threads at once. |
System.Int32 |
workerCount |
Number of worker threads. By default SystemInfo.processorCount is used. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TOut> |
Type Parameters
Name | Description |
---|---|
TIn |
Type of the input values. |
TOut |
Type of the output values. |
Exceptions
Type | Condition |
---|---|
System.Reflection.TargetInvocationException |
An exception was thrown inside one of the threads, and the operation was aborted. |
System.ArgumentException |
Need at least 1 workerCount. |
Apply a function to a collection of data by spreading the work on multiple threads. Outputs of the functions are returned to the current thread and yielded one by one.
Declaration
public static IEnumerable<TOut> RunParallel<TIn, TOut>(this IList<TIn> data, Func<TIn, TOut> work, int workerCount = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<TIn> |
data |
Input values for the work function. |
System.Func<TIn, TOut> |
work |
Function to apply to the data on multiple threads at once. |
System.Int32 |
workerCount |
Number of worker threads. By default SystemInfo.processorCount is used. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TOut> |
Type Parameters
Name | Description |
---|---|
TIn |
Type of the input values. |
TOut |
Type of the output values. |
Exceptions
Type | Condition |
---|---|
System.Reflection.TargetInvocationException |
An exception was thrown inside one of the threads, and the operation was aborted. |
System.ArgumentException |
Need at least 1 workerCount. |