Class ThreadingExtensions

Convenience extensions for utilizing multiple threads and using the ThreadingHelper.

Inheritance
System.Object ThreadingExtensions
Inherited Members
System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace: BepInEx
Assembly: BepInEx.dll
Syntax
public static class ThreadingExtensions

Methods

RunParallel<TIn, TOut>(IEnumerable<TIn>, Func<TIn, TOut>, Int32)

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.

RunParallel<TIn, TOut>(IList<TIn>, Func<TIn, TOut>, Int32)

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.