| ParallelForEachT Method |
Executes a for-each loop where each iteration can potentially occur in parallel with others.
Namespace: DigitalRune.ThreadingAssembly: DigitalRune (in DigitalRune.dll) Version: 1.20.0.0 (1.20.1.14552)
Syntax public static void ForEach<T>(
IEnumerable<T> collection,
Action<T> action
)
Public Shared Sub ForEach(Of T) (
collection As IEnumerable(Of T),
action As Action(Of T)
)
public:
generic<typename T>
static void ForEach(
IEnumerable<T>^ collection,
Action<T>^ action
)
static member ForEach :
collection : IEnumerable<'T> *
action : Action<'T> -> unit
Parameters
- collection
- Type: System.Collections.GenericIEnumerableT
The enumerable data source. - action
- Type: SystemActionT
The method to execute at each iteration. The item to process is supplied as the parameter.
Type Parameters
- T
- The type of item to iterate over.
Exceptions Remarks
The parallel foreach-loop has a few disadvantages: Enumerating the sequence in parallel
requires locking. In addition, creating an
IEnumeratorT object allocates
memory on the managed heap. It is therefore recommended to use the parallel for-loop instead
of the parallel for-each loop where possible.
See Also