Parallel.ForEach 메서드
정의
반복이 병렬로 실행될 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation in which iterations may run in parallel.
오버로드
ForEach<TSource,TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource,TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
64비트 인덱스와 스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource,TLocal>(Partitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource,TLocal>(OrderablePartitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
64비트 인덱스와 스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource,TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource,TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource,TLocal>(Partitioner<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource,TLocal>(OrderablePartitioner<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource>) |
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있는 |
ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource,ParallelLoopState>) |
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource>(IEnumerable<TSource>, Action<TSource,ParallelLoopState>) |
반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource>) |
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있는 |
ForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource,ParallelLoopState>) |
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource>(OrderablePartitioner<TSource>, ParallelOptions, Action<TSource,ParallelLoopState,Int64>) |
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource>(IEnumerable<TSource>, Action<TSource>) |
반복이 병렬로 실행될 수 있는 |
ForEach<TSource>(IEnumerable<TSource>, Action<TSource,ParallelLoopState,Int64>) |
64비트 인덱스를 사용하여 반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource>(Partitioner<TSource>, Action<TSource>) |
반복이 병렬로 실행될 수 있는 |
ForEach<TSource>(Partitioner<TSource>, Action<TSource,ParallelLoopState>) |
반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource>(OrderablePartitioner<TSource>, Action<TSource,ParallelLoopState,Int64>) |
반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource,ParallelLoopState,Int64>) |
64비트 인덱스를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 |
ForEach<TSource,TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>)
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with thread-local data on an IEnumerable in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource, typename TLocal>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Func<TLocal> ^ localInit, Func<TSource, System::Threading::Tasks::ParallelLoopState ^, TLocal, TLocal> ^ body, Action<TLocal> ^ localFinally);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource,TLocal> (System.Collections.Generic.IEnumerable<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Func<TLocal> localInit, Func<TSource,System.Threading.Tasks.ParallelLoopState,TLocal,TLocal> body, Action<TLocal> localFinally);
static member ForEach : seq<'Source> * System.Threading.Tasks.ParallelOptions * Func<'Local> * Func<'Source, System.Threading.Tasks.ParallelLoopState, 'Local, 'Local> * Action<'Local> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource, TLocal) (source As IEnumerable(Of TSource), parallelOptions As ParallelOptions, localInit As Func(Of TLocal), body As Func(Of TSource, ParallelLoopState, TLocal, TLocal), localFinally As Action(Of TLocal)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
- TLocal
스레드 로컬 데이터의 형식입니다.The type of the thread-local data.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- localInit
- Func<TLocal>
각 작업에 대한 로컬 데이터의 초기 상태를 반환하는 함수 대리자입니다.The function delegate that returns the initial state of the local data for each task.
- body
- Func<TSource,ParallelLoopState,TLocal,TLocal>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
- localFinally
- Action<TLocal>
각 작업의 로컬 상태에 대해 최종 동작을 수행하는 대리자입니다.The delegate that performs a final action on the local state of each task.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
또는-or-
localInit
인수가 null
인 경우The localInit
argument is null
.
또는-or-
localFinally
인수가 null
인 경우The localFinally
argument is null
.
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 이 클래스에는 현재 요소, 외부 ParallelLoopState 에서 루프를 중단 하는 데 사용할 수 있는 인스턴스, 동일한 스레드에서 실행 되는 반복 간에 공유 될 수 있는 일부 로컬 상태와 같은 매개 변수가 제공 됩니다.It is provided with the following parameters: the current element, a ParallelLoopState instance that may be used to break out of the loop prematurely, and some local state that may be shared amongst iterations that execute on the same thread.
localInit
대리자는 루프의 실행에 참여 하는 각 작업에 대해 한 번 호출 되 고 각 작업에 대 한 초기 로컬 상태를 반환 합니다.The localInit
delegate is invoked once for each task that participates in the loop's execution and returns the initial local state for each of those tasks. 이러한 초기 상태는 body
각 작업에 대 한 첫 번째 호출에 전달 됩니다.These initial states are passed to the first body
invocations on each task. 그런 다음, 이후의 모든 본문 호출은 다음 본문 호출에 전달 되는 수정 된 상태 값을 반환 합니다.Then, every subsequent body invocation returns a possibly modified state value that is passed to the next body invocation. 마지막으로 각 작업의 마지막 본문 호출은 대리자에 전달 되는 상태 값을 반환 합니다 localFinally
.Finally, the last body invocation on each task returns a state value that is passed to the localFinally
delegate. localFinally
대리자는 각 작업의 로컬 상태에 대해 최종 동작을 수행 하기 위해 스레드별로 한 번 호출 됩니다.The localFinally
delegate is invoked once per thread to perform a final action on each task's local state. 이 대리자는 여러 작업에서 동시에 호출 될 수 있습니다. 따라서 공유 변수에 대 한 액세스를 동기화 해야 합니다.This delegate might be invoked concurrently on multiple tasks; therefore, you must synchronize access to any shared variables.
Parallel.ForEach메서드는 기존 태스크가 완료 되 고 새 작업으로 대체 될 때 실행 수명 동안 스레드 보다 많은 작업을 사용할 수 있습니다.The Parallel.ForEach method may use more tasks than threads over the lifetime of its execution, as existing tasks complete and are replaced by new tasks. 이렇게 하면 기본 TaskScheduler 개체가 루프를 처리 하는 스레드를 추가, 변경 또는 제거할 수 있습니다.This gives the underlying TaskScheduler object the chance to add, change, or remove threads that service the loop.
추가 정보
적용 대상
ForEach<TSource,TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>)
64비트 인덱스와 스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with thread-local data and 64-bit indexes on an IEnumerable in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource, typename TLocal>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Func<TLocal> ^ localInit, Func<TSource, System::Threading::Tasks::ParallelLoopState ^, long, TLocal, TLocal> ^ body, Action<TLocal> ^ localFinally);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource,TLocal> (System.Collections.Generic.IEnumerable<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Func<TLocal> localInit, Func<TSource,System.Threading.Tasks.ParallelLoopState,long,TLocal,TLocal> body, Action<TLocal> localFinally);
static member ForEach : seq<'Source> * System.Threading.Tasks.ParallelOptions * Func<'Local> * Func<'Source, System.Threading.Tasks.ParallelLoopState, int64, 'Local, 'Local> * Action<'Local> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource, TLocal) (source As IEnumerable(Of TSource), parallelOptions As ParallelOptions, localInit As Func(Of TLocal), body As Func(Of TSource, ParallelLoopState, Long, TLocal, TLocal), localFinally As Action(Of TLocal)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
- TLocal
스레드 로컬 데이터의 형식입니다.The type of the thread-local data.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- localInit
- Func<TLocal>
각 작업에 대한 로컬 데이터의 초기 상태를 반환하는 함수 대리자입니다.The function delegate that returns the initial state of the local data for each task.
- body
- Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
- localFinally
- Action<TLocal>
각 작업의 로컬 상태에 대해 최종 동작을 수행하는 대리자입니다.The delegate that performs a final action on the local state of each task.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
또는-or-
localInit
인수가 null
인 경우The localInit
argument is null
.
또는-or-
localFinally
인수가 null
인 경우The localFinally
argument is null
.
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 이 매개 변수는 현재 요소, 외부 ParallelLoopState 에서 루프를 중단 하는 데 사용할 수 있는 인스턴스, 현재 요소의 인덱스 ( Int64 ) 및 동일한 스레드에서 실행 되는 반복 간에 공유 될 수 있는 일부 로컬 상태와 같은 매개 변수를 제공 합니다.It is provided with the following parameters: the current element, a ParallelLoopState instance that may be used to break out of the loop prematurely, the current element's index (Int64), and some local state that may be shared amongst iterations that execute on the same thread.
localInit
대리자는 루프의 실행에 참여 하는 각 작업에 대해 한 번 호출 되 고 각 작업에 대 한 초기 로컬 상태를 반환 합니다.The localInit
delegate is invoked once for each task that participates in the loop's execution and returns the initial local state for each of those tasks. 이러한 초기 상태는 body
각 작업에 대 한 첫 번째 호출에 전달 됩니다.These initial states are passed to the first body
invocations on each task. 그런 다음, 이후의 모든 본문 호출은 다음 본문 호출에 전달 되는 수정 된 상태 값을 반환 합니다.Then, every subsequent body invocation returns a possibly modified state value that is passed to the next body invocation. 마지막으로 각 작업의 마지막 본문 호출은 대리자에 전달 되는 상태 값을 반환 합니다 localFinally
.Finally, the last body invocation on each task returns a state value that is passed to the localFinally
delegate. localFinally
대리자는 각 작업의 로컬 상태에 대해 최종 동작을 수행 하기 위해 스레드별로 한 번 호출 됩니다.The localFinally
delegate is invoked once per thread to perform a final action on each task's local state. 이 대리자는 여러 작업에서 동시에 호출 될 수 있습니다. 따라서 공유 변수에 대 한 액세스를 동기화 해야 합니다.This delegate might be invoked concurrently on multiple tasks; therefore, you must synchronize access to any shared variables.
Parallel.ForEach메서드는 기존 태스크가 완료 되 고 새 작업으로 대체 될 때 실행 수명 동안 스레드 보다 많은 작업을 사용할 수 있습니다.The Parallel.ForEach method may use more tasks than threads over the lifetime of its execution, as existing tasks complete and are replaced by new tasks. 이렇게 하면 기본 TaskScheduler 개체가 루프를 처리 하는 스레드를 추가, 변경 또는 제거할 수 있습니다.This gives the underlying TaskScheduler object the chance to add, change, or remove threads that service the loop.
추가 정보
적용 대상
ForEach<TSource,TLocal>(Partitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>)
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 Partitioner에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with thread-local data on a Partitioner in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource, typename TLocal>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::Partitioner<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Func<TLocal> ^ localInit, Func<TSource, System::Threading::Tasks::ParallelLoopState ^, TLocal, TLocal> ^ body, Action<TLocal> ^ localFinally);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource,TLocal> (System.Collections.Concurrent.Partitioner<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Func<TLocal> localInit, Func<TSource,System.Threading.Tasks.ParallelLoopState,TLocal,TLocal> body, Action<TLocal> localFinally);
static member ForEach : System.Collections.Concurrent.Partitioner<'Source> * System.Threading.Tasks.ParallelOptions * Func<'Local> * Func<'Source, System.Threading.Tasks.ParallelLoopState, 'Local, 'Local> * Action<'Local> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource, TLocal) (source As Partitioner(Of TSource), parallelOptions As ParallelOptions, localInit As Func(Of TLocal), body As Func(Of TSource, ParallelLoopState, TLocal, TLocal), localFinally As Action(Of TLocal)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
- TLocal
스레드 로컬 데이터의 형식입니다.The type of the thread-local data.
매개 변수
- source
- Partitioner<TSource>
원래 데이터 소스가 포함된 Partitioner입니다.The partitioner that contains the original data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- localInit
- Func<TLocal>
각 작업에 대한 로컬 데이터의 초기 상태를 반환하는 함수 대리자입니다.The function delegate that returns the initial state of the local data for each task.
- body
- Func<TSource,ParallelLoopState,TLocal,TLocal>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
- localFinally
- Action<TLocal>
각 작업의 로컬 상태에 대해 최종 동작을 수행하는 대리자입니다.The delegate that performs a final action on the local state of each task.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
또는-or-
localInit
인수가 null
인 경우The localInit
argument is null
.
또는-or-
localFinally
인수가 null
인 경우The localFinally
argument is null
.
source
SupportsDynamicPartitions의 Partitioner 속성은 false
를 반환하거나 파티셔너가 null
파티션을 반환합니다.The SupportsDynamicPartitions property in the source
Partitioner returns false
or the partitioner returns null
partitions.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The ForEach method expects custom partitioners to support dynamic partitioning. 이 오버 로드는 정적 범위 분할의 이점을 누릴 수 있는 작은 루프 본문이 있는 시나리오에 제공 됩니다.This overload is provided for scenarios with small loop bodies that might benefit from static range partitioning. 파티 셔 너는 동적 파티션을 지원 해야 합니다.Partitioners must support dynamic partitions. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
localInit
대리자는 루프의 실행에 참여 하는 각 작업에 대해 한 번 호출 되 고 각 작업에 대 한 초기 로컬 상태를 반환 합니다.The localInit
delegate is invoked once for each task that participates in the loop's execution and returns the initial local state for each of those tasks. 이러한 초기 상태는 body
각 작업에 대 한 첫 번째 호출에 전달 됩니다.These initial states are passed to the first body
invocations on each task. 그런 다음, 이후의 모든 본문 호출은 다음 본문 호출에 전달 되는 수정 된 상태 값을 반환 합니다.Then, every subsequent body invocation returns a possibly modified state value that is passed to the next body invocation. 마지막으로 각 작업의 마지막 본문 호출은 대리자에 전달 되는 상태 값을 반환 합니다 localFinally
.Finally, the last body invocation on each task returns a state value that is passed to the localFinally
delegate. localFinally
대리자는 각 작업의 로컬 상태에 대해 최종 동작을 수행 하는 작업당 한 번 호출 됩니다.The localFinally
delegate is invoked once per task to perform a final action on each task's local state. 이 대리자는 여러 작업에서 동시에 호출 될 수 있습니다. 따라서 공유 변수에 대 한 액세스를 동기화 해야 합니다.This delegate might be invoked concurrently on multiple tasks; therefore, you must synchronize access to any shared variables.
Parallel.ForEach메서드는 기존 태스크가 완료 되 고 새 작업으로 대체 될 때 실행 수명 동안 스레드 보다 많은 작업을 사용할 수 있습니다.The Parallel.ForEach method may use more tasks than threads over the lifetime of its execution, as existing tasks complete and are replaced by new tasks. 이렇게 하면 기본 TaskScheduler 개체가 루프를 처리 하는 스레드를 추가, 변경 또는 제거할 수 있습니다.This gives the underlying TaskScheduler object the chance to add, change, or remove threads that service the loop.
추가 정보
적용 대상
ForEach<TSource,TLocal>(OrderablePartitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>)
64비트 인덱스와 스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 OrderablePartitioner<TSource>에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with 64-bit indexes and with thread-local data on a OrderablePartitioner<TSource> in which iterations may run in parallel , loop options can be configured, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource, typename TLocal>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::OrderablePartitioner<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Func<TLocal> ^ localInit, Func<TSource, System::Threading::Tasks::ParallelLoopState ^, long, TLocal, TLocal> ^ body, Action<TLocal> ^ localFinally);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource,TLocal> (System.Collections.Concurrent.OrderablePartitioner<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Func<TLocal> localInit, Func<TSource,System.Threading.Tasks.ParallelLoopState,long,TLocal,TLocal> body, Action<TLocal> localFinally);
static member ForEach : System.Collections.Concurrent.OrderablePartitioner<'Source> * System.Threading.Tasks.ParallelOptions * Func<'Local> * Func<'Source, System.Threading.Tasks.ParallelLoopState, int64, 'Local, 'Local> * Action<'Local> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource, TLocal) (source As OrderablePartitioner(Of TSource), parallelOptions As ParallelOptions, localInit As Func(Of TLocal), body As Func(Of TSource, ParallelLoopState, Long, TLocal, TLocal), localFinally As Action(Of TLocal)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
- TLocal
스레드 로컬 데이터의 형식입니다.The type of the thread-local data.
매개 변수
원래 데이터 소스가 포함된 정렬할 수 있는 파티셔너입니다.The orderable partitioner that contains the original data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- localInit
- Func<TLocal>
각 작업에 대한 로컬 데이터의 초기 상태를 반환하는 함수 대리자입니다.The function delegate that returns the initial state of the local data for each task.
- body
- Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
- localFinally
- Action<TLocal>
각 작업의 로컬 상태에 대해 최종 동작을 수행하는 대리자입니다.The delegate that performs a final action on the local state of each task.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
또는-or-
localInit
또는 localFinally
인수가 null
인 경우The localInit
or localFinally
argument is null
.
source
SupportsDynamicPartitions의 Partitioner 속성은 false
를 반환하거나 파티셔너가 null
파티션을 반환합니다.The SupportsDynamicPartitions property in the source
Partitioner returns false
or the partitioner returns null
partitions.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The ForEach method expects custom partitioners to support dynamic partitioning. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
localInit
대리자는 루프의 실행에 참여 하는 각 작업에 대해 한 번 호출 되 고 각 작업에 대 한 초기 로컬 상태를 반환 합니다.The localInit
delegate is invoked once for each task that participates in the loop's execution and returns the initial local state for each of those tasks. 이러한 초기 상태는 body
각 작업에 대 한 첫 번째 호출에 전달 됩니다.These initial states are passed to the first body
invocations on each task. 그런 다음, 이후의 모든 본문 호출은 다음 본문 호출에 전달 되는 수정 된 상태 값을 반환 합니다.Then, every subsequent body invocation returns a possibly modified state value that is passed to the next body invocation. 마지막으로 각 스레드의 마지막 본문 호출이 대리자에 전달 되는 상태 값을 반환 합니다 localFinally
.Finally, the last body invocation on each thread returns a state value that is passed to the localFinally
delegate. localFinally
대리자는 각 작업의 로컬 상태에 대해 최종 동작을 수행 하는 작업당 한 번 호출 됩니다.The localFinally
delegate is invoked once per task to perform a final action on each task's local state. 이 대리자는 여러 작업에서 동시에 호출 될 수 있습니다. 따라서 공유 변수에 대 한 액세스를 동기화 해야 합니다.This delegate might be invoked concurrently on multiple tasks; therefore, you must synchronize access to any shared variables.
Parallel.ForEach메서드는 기존 태스크가 완료 되 고 새 작업으로 대체 될 때 실행 수명 동안 스레드 보다 많은 작업을 사용할 수 있습니다.The Parallel.ForEach method may use more tasks than threads over the lifetime of its execution, as existing tasks complete and are replaced by new tasks. 이렇게 하면 기본 TaskScheduler 개체가 루프를 처리 하는 스레드를 추가, 변경 또는 제거할 수 있습니다.This gives the underlying TaskScheduler object the chance to add, change, or remove threads that service the loop.
추가 정보
적용 대상
ForEach<TSource,TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>)
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with thread-local data on an IEnumerable in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource, typename TLocal>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TLocal> ^ localInit, Func<TSource, System::Threading::Tasks::ParallelLoopState ^, TLocal, TLocal> ^ body, Action<TLocal> ^ localFinally);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource,TLocal> (System.Collections.Generic.IEnumerable<TSource> source, Func<TLocal> localInit, Func<TSource,System.Threading.Tasks.ParallelLoopState,TLocal,TLocal> body, Action<TLocal> localFinally);
static member ForEach : seq<'Source> * Func<'Local> * Func<'Source, System.Threading.Tasks.ParallelLoopState, 'Local, 'Local> * Action<'Local> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource, TLocal) (source As IEnumerable(Of TSource), localInit As Func(Of TLocal), body As Func(Of TSource, ParallelLoopState, TLocal, TLocal), localFinally As Action(Of TLocal)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
- TLocal
스레드 로컬 데이터의 형식입니다.The type of the thread-local data.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- localInit
- Func<TLocal>
각 작업에 대한 로컬 데이터의 초기 상태를 반환하는 함수 대리자입니다.The function delegate that returns the initial state of the local data for each task.
- body
- Func<TSource,ParallelLoopState,TLocal,TLocal>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
- localFinally
- Action<TLocal>
각 작업의 로컬 상태에 대해 최종 동작을 수행하는 대리자입니다.The delegate that performs a final action on the local state of each task.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
또는-or-
localInit
인수가 null
인 경우The localInit
argument is null
.
또는-or-
localFinally
인수가 null
인 경우The localFinally
argument is null
.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
예제
다음 예제에서는 ForEach 로컬 상태에서 메서드를 사용 하는 방법을 보여 줍니다.The following example shows how to use a ForEach method with local state:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
class ForEachWithThreadLocal
{
// Demonstrated features:
// Parallel.ForEach()
// Thread-local state
// Expected results:
// This example sums up the elements of an int[] in parallel.
// Each thread maintains a local sum. When a thread is initialized, that local sum is set to 0.
// On every iteration the current element is added to the local sum.
// When a thread is done, it safely adds its local sum to the global sum.
// After the loop is complete, the global sum is printed out.
// Documentation:
// http://msdn.microsoft.com/library/dd990270(VS.100).aspx
static void Main()
{
// The sum of these elements is 40.
int[] input = { 4, 1, 6, 2, 9, 5, 10, 3 };
int sum = 0;
try
{
Parallel.ForEach(
input, // source collection
() => 0, // thread local initializer
(n, loopState, localSum) => // body
{
localSum += n;
Console.WriteLine("Thread={0}, n={1}, localSum={2}", Thread.CurrentThread.ManagedThreadId, n, localSum);
return localSum;
},
(localSum) => Interlocked.Add(ref sum, localSum) // thread local aggregator
);
Console.WriteLine("\nSum={0}", sum);
}
// No exception is expected in this example, but if one is still thrown from a task,
// it will be wrapped in AggregateException and propagated to the main thread.
catch (AggregateException e)
{
Console.WriteLine("Parallel.ForEach has thrown an exception. THIS WAS NOT EXPECTED.\n{0}", e);
}
}
}
Imports System.Threading
Imports System.Threading.Tasks
Module ForEachDemo
' Demonstrated features:
' Parallel.ForEach()
' Thread-local state
' Expected results:
' This example sums up the elements of an int[] in parallel.
' Each thread maintains a local sum. When a thread is initialized, that local sum is set to 0.
' On every iteration the current element is added to the local sum.
' When a thread is done, it safely adds its local sum to the global sum.
' After the loop is complete, the global sum is printed out.
' Documentation:
' http://msdn.microsoft.com/library/dd990270(VS.100).aspx
Private Sub ForEachDemo()
' The sum of these elements is 40.
Dim input As Integer() = {4, 1, 6, 2, 9, 5, _
10, 3}
Dim sum As Integer = 0
Try
' source collection
Parallel.ForEach(input,
Function()
' thread local initializer
Return 0
End Function,
Function(n, loopState, localSum)
' body
localSum += n
Console.WriteLine("Thread={0}, n={1}, localSum={2}", Thread.CurrentThread.ManagedThreadId, n, localSum)
Return localSum
End Function,
Sub(localSum)
' thread local aggregator
Interlocked.Add(sum, localSum)
End Sub)
Console.WriteLine(vbLf & "Sum={0}", sum)
Catch e As AggregateException
' No exception is expected in this example, but if one is still thrown from a task,
' it will be wrapped in AggregateException and propagated to the main thread.
Console.WriteLine("Parallel.ForEach has thrown an exception. THIS WAS NOT EXPECTED." & vbLf & "{0}", e)
End Try
End Sub
End Module
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 이 클래스에는 현재 요소, 외부 ParallelLoopState 에서 루프를 중단 하는 데 사용할 수 있는 인스턴스, 동일한 스레드에서 실행 되는 반복 간에 공유 될 수 있는 일부 로컬 상태와 같은 매개 변수가 제공 됩니다.It is provided with the following parameters: the current element, a ParallelLoopState instance that may be used to break out of the loop prematurely, and some local state that may be shared amongst iterations that execute on the same thread.
localInit
대리자는 루프의 실행에 참여 하는 각 작업에 대해 한 번 호출 되 고 각 작업에 대 한 초기 로컬 상태를 반환 합니다.The localInit
delegate is invoked once for each task that participates in the loop's execution and returns the initial local state for each of those tasks. 이러한 초기 상태는 body
각 작업에 대 한 첫 번째 호출에 전달 됩니다.These initial states are passed to the first body
invocations on each task. 그런 다음, 이후의 모든 본문 호출은 다음 본문 호출에 전달 되는 수정 된 상태 값을 반환 합니다.Then, every subsequent body invocation returns a possibly modified state value that is passed to the next body invocation. 마지막으로 각 작업의 마지막 본문 호출은 대리자에 전달 되는 상태 값을 반환 합니다 localFinally
.Finally, the last body invocation on each task returns a state value that is passed to the localFinally
delegate. localFinally
대리자는 각 작업의 로컬 상태에 대해 최종 동작을 수행 하기 위해 스레드별로 한 번 호출 됩니다.The localFinally
delegate is invoked once per thread to perform a final action on each task's local state. 이 대리자는 여러 작업에서 동시에 호출 될 수 있습니다. 따라서 공유 변수에 대 한 액세스를 동기화 해야 합니다.This delegate might be invoked concurrently on multiple tasks; therefore, you must synchronize access to any shared variables.
Parallel.ForEach메서드는 기존 태스크가 완료 되 고 새 작업으로 대체 될 때 실행 수명 동안 스레드 보다 많은 작업을 사용할 수 있습니다.The Parallel.ForEach method may use more tasks than threads over the lifetime of its execution, as existing tasks complete and are replaced by new tasks. 이렇게 하면 기본 TaskScheduler 개체가 루프를 처리 하는 스레드를 추가, 변경 또는 제거할 수 있습니다.This gives the underlying TaskScheduler object the chance to add, change, or remove threads that service the loop.
추가 정보
적용 대상
ForEach<TSource,TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>)
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with thread-local data on an IEnumerable in which iterations may run in parallel and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource, typename TLocal>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TLocal> ^ localInit, Func<TSource, System::Threading::Tasks::ParallelLoopState ^, long, TLocal, TLocal> ^ body, Action<TLocal> ^ localFinally);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource,TLocal> (System.Collections.Generic.IEnumerable<TSource> source, Func<TLocal> localInit, Func<TSource,System.Threading.Tasks.ParallelLoopState,long,TLocal,TLocal> body, Action<TLocal> localFinally);
static member ForEach : seq<'Source> * Func<'Local> * Func<'Source, System.Threading.Tasks.ParallelLoopState, int64, 'Local, 'Local> * Action<'Local> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource, TLocal) (source As IEnumerable(Of TSource), localInit As Func(Of TLocal), body As Func(Of TSource, ParallelLoopState, Long, TLocal, TLocal), localFinally As Action(Of TLocal)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
- TLocal
스레드 로컬 데이터의 형식입니다.The type of the thread-local data.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- localInit
- Func<TLocal>
각 작업에 대한 로컬 데이터의 초기 상태를 반환하는 함수 대리자입니다.The function delegate that returns the initial state of the local data for each task.
- body
- Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
- localFinally
- Action<TLocal>
각 작업의 로컬 상태에 대해 최종 동작을 수행하는 대리자입니다.The delegate that performs a final action on the local state of each task.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
또는-or-
localInit
인수가 null
인 경우The localInit
argument is null
.
또는-or-
localFinally
인수가 null
인 경우The localFinally
argument is null
.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 이 매개 변수는 현재 요소, 외부 ParallelLoopState 에서 루프를 중단 하는 데 사용할 수 있는 인스턴스, 현재 요소의 인덱스 ( Int64 ) 및 동일한 스레드에서 실행 되는 반복 간에 공유 될 수 있는 일부 로컬 상태와 같은 매개 변수를 제공 합니다.It is provided with the following parameters: the current element, a ParallelLoopState instance that may be used to break out of the loop prematurely, the current element's index (Int64), and some local state that may be shared amongst iterations that execute on the same thread.
localInit
대리자는 루프의 실행에 참여 하는 각 작업에 대해 한 번 호출 되 고 각 작업에 대 한 초기 로컬 상태를 반환 합니다.The localInit
delegate is invoked once for each task that participates in the loop's execution and returns the initial local state for each of those tasks. 이러한 초기 상태는 body
각 작업에 대 한 첫 번째 호출에 전달 됩니다.These initial states are passed to the first body
invocations on each task. 그런 다음, 이후의 모든 본문 호출은 다음 본문 호출에 전달 되는 수정 된 상태 값을 반환 합니다.Then, every subsequent body invocation returns a possibly modified state value that is passed to the next body invocation. 마지막으로 각 작업의 마지막 본문 호출은 대리자에 전달 되는 상태 값을 반환 합니다 localFinally
.Finally, the last body invocation on each task returns a state value that is passed to the localFinally
delegate. localFinally
대리자는 각 작업의 로컬 상태에 대해 최종 동작을 수행 하는 작업당 한 번 호출 됩니다.The localFinally
delegate is invoked once per task to perform a final action on each task's local state. 이 대리자는 여러 작업에서 동시에 호출 될 수 있습니다. 따라서 공유 변수에 대 한 액세스를 동기화 해야 합니다.This delegate might be invoked concurrently on multiple tasks; therefore, you must synchronize access to any shared variables.
Parallel.ForEach메서드는 기존 태스크가 완료 되 고 새 작업으로 대체 될 때 실행 수명 동안 스레드 보다 많은 작업을 사용할 수 있습니다.The Parallel.ForEach method may use more tasks than threads over the lifetime of its execution, as existing tasks complete and are replaced by new tasks. 이렇게 하면 기본 TaskScheduler 개체가 루프를 처리 하는 스레드를 추가, 변경 또는 제거할 수 있습니다.This gives the underlying TaskScheduler object the chance to add, change, or remove threads that service the loop.
추가 정보
적용 대상
ForEach<TSource,TLocal>(Partitioner<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>)
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 Partitioner에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with thread-local data on a Partitioner in which iterations may run in parallel and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource, typename TLocal>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::Partitioner<TSource> ^ source, Func<TLocal> ^ localInit, Func<TSource, System::Threading::Tasks::ParallelLoopState ^, TLocal, TLocal> ^ body, Action<TLocal> ^ localFinally);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource,TLocal> (System.Collections.Concurrent.Partitioner<TSource> source, Func<TLocal> localInit, Func<TSource,System.Threading.Tasks.ParallelLoopState,TLocal,TLocal> body, Action<TLocal> localFinally);
static member ForEach : System.Collections.Concurrent.Partitioner<'Source> * Func<'Local> * Func<'Source, System.Threading.Tasks.ParallelLoopState, 'Local, 'Local> * Action<'Local> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource, TLocal) (source As Partitioner(Of TSource), localInit As Func(Of TLocal), body As Func(Of TSource, ParallelLoopState, TLocal, TLocal), localFinally As Action(Of TLocal)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
- TLocal
스레드 로컬 데이터의 형식입니다.The type of the thread-local data.
매개 변수
- source
- Partitioner<TSource>
원래 데이터 소스가 포함된 Partitioner입니다.The partitioner that contains the original data source.
- localInit
- Func<TLocal>
각 작업에 대한 로컬 데이터의 초기 상태를 반환하는 함수 대리자입니다.The function delegate that returns the initial state of the local data for each task.
- body
- Func<TSource,ParallelLoopState,TLocal,TLocal>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
- localFinally
- Action<TLocal>
각 작업의 로컬 상태에 대해 최종 동작을 수행하는 대리자입니다.The delegate that performs a final action on the local state of each task.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
또는-or-
localInit
인수가 null
인 경우The localInit
argument is null
.
또는-or-
localFinally
인수가 null
인 경우The localFinally
argument is null
.
source
SupportsDynamicPartitions의 Partitioner 속성은 false
를 반환하거나 파티셔너가 null
파티션을 반환합니다.The SupportsDynamicPartitions property in the source
Partitioner returns false
or the partitioner returns null
partitions.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The ForEach method expects custom partitioners to support dynamic partitioning. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
localInit
대리자는 루프의 실행에 참여 하는 각 스레드에 대해 한 번씩 호출 되 고 각 작업에 대 한 초기 로컬 상태를 반환 합니다.The localInit
delegate is invoked once for each thread that participates in the loop's execution and returns the initial local state for each of those tasks. 이러한 초기 상태는 body
각 작업에 대 한 첫 번째 호출에 전달 됩니다.These initial states are passed to the first body
invocations on each task. 그런 다음, 이후의 모든 본문 호출은 다음 본문 호출에 전달 되는 수정 된 상태 값을 반환 합니다.Then, every subsequent body invocation returns a possibly modified state value that is passed to the next body invocation. 마지막으로 각 작업의 마지막 본문 호출은 대리자에 전달 되는 상태 값을 반환 합니다 localFinally
.Finally, the last body invocation on each task returns a state value that is passed to the localFinally
delegate. localFinally
대리자는 각 작업의 로컬 상태에 대해 최종 동작을 수행 하는 작업당 한 번 호출 됩니다.The localFinally
delegate is invoked once per task to perform a final action on each task's local state. 이 대리자는 여러 작업에서 동시에 호출 될 수 있습니다. 따라서 공유 변수에 대 한 액세스를 동기화 해야 합니다.This delegate might be invoked concurrently on multiple tasks; therefore, you must synchronize access to any shared variables.
Parallel.ForEach메서드는 기존 태스크가 완료 되 고 새 작업으로 대체 될 때 실행 수명 동안 스레드 보다 많은 작업을 사용할 수 있습니다.The Parallel.ForEach method may use more tasks than threads over the lifetime of its execution, as existing tasks complete and are replaced by new tasks. 이렇게 하면 기본 TaskScheduler 개체가 루프를 처리 하는 스레드를 추가, 변경 또는 제거할 수 있습니다.This gives the underlying TaskScheduler object the chance to add, change, or remove threads that service the loop.
추가 정보
적용 대상
ForEach<TSource,TLocal>(OrderablePartitioner<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>)
스레드 로컬 데이터를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 OrderablePartitioner<TSource>에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with thread-local data on a OrderablePartitioner<TSource> in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource, typename TLocal>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::OrderablePartitioner<TSource> ^ source, Func<TLocal> ^ localInit, Func<TSource, System::Threading::Tasks::ParallelLoopState ^, long, TLocal, TLocal> ^ body, Action<TLocal> ^ localFinally);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource,TLocal> (System.Collections.Concurrent.OrderablePartitioner<TSource> source, Func<TLocal> localInit, Func<TSource,System.Threading.Tasks.ParallelLoopState,long,TLocal,TLocal> body, Action<TLocal> localFinally);
static member ForEach : System.Collections.Concurrent.OrderablePartitioner<'Source> * Func<'Local> * Func<'Source, System.Threading.Tasks.ParallelLoopState, int64, 'Local, 'Local> * Action<'Local> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource, TLocal) (source As OrderablePartitioner(Of TSource), localInit As Func(Of TLocal), body As Func(Of TSource, ParallelLoopState, Long, TLocal, TLocal), localFinally As Action(Of TLocal)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
- TLocal
스레드 로컬 데이터의 형식입니다.The type of the thread-local data.
매개 변수
원래 데이터 소스가 포함된 정렬할 수 있는 파티셔너입니다.The orderable partitioner that contains the original data source.
- localInit
- Func<TLocal>
각 작업에 대한 로컬 데이터의 초기 상태를 반환하는 함수 대리자입니다.The function delegate that returns the initial state of the local data for each task.
- body
- Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
- localFinally
- Action<TLocal>
각 작업의 로컬 상태에 대해 최종 동작을 수행하는 대리자입니다.The delegate that performs a final action on the local state of each task.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
또는-or-
localInit
인수가 null
인 경우The localInit
argument is null
.
또는-or-
localFinally
인수가 null
인 경우The localFinally
argument is null
.
source
SupportsDynamicPartitions의 Partitioner 속성은 false
를 반환하거나 파티셔너가 null
파티션을 반환합니다.The SupportsDynamicPartitions property in the source
Partitioner returns false
or the partitioner returns null
partitions.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The ForEach method expects custom partitioners to support dynamic partitioning. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
localInit
대리자는 루프의 실행에 참여 하는 각 작업에 대해 한 번 호출 되 고 각 작업에 대 한 초기 로컬 상태를 반환 합니다.The localInit
delegate is invoked once for each task that participates in the loop's execution and returns the initial local state for each of those tasks. 이러한 초기 상태는 body
각 작업에 대 한 첫 번째 호출에 전달 됩니다.These initial states are passed to the first body
invocations on each task. 그런 다음, 이후의 모든 본문 호출은 다음 본문 호출에 전달 되는 수정 된 상태 값을 반환 합니다.Then, every subsequent body invocation returns a possibly modified state value that is passed to the next body invocation. 마지막으로 각 작업의 마지막 본문 호출은 대리자에 전달 되는 상태 값을 반환 합니다 localFinally
.Finally, the last body invocation on each task returns a state value that is passed to the localFinally
delegate. localFinally
대리자는 각 작업의 로컬 상태에 대해 최종 동작을 수행 하는 작업당 한 번 호출 됩니다.The localFinally
delegate is invoked once per task to perform a final action on each task's local state. 이 대리자는 여러 작업에서 동시에 호출 될 수 있습니다. 따라서 공유 변수에 대 한 액세스를 동기화 해야 합니다.This delegate might be invoked concurrently on multiple tasks; therefore, you must synchronize access to any shared variables.
Parallel.ForEach메서드는 기존 태스크가 완료 되 고 새 작업으로 대체 될 때 실행 수명 동안 스레드 보다 많은 작업을 사용할 수 있습니다.The Parallel.ForEach method may use more tasks than threads over the lifetime of its execution, as existing tasks complete and are replaced by new tasks. 이렇게 하면 기본 TaskScheduler 개체가 루프를 처리 하는 스레드를 추가, 변경 또는 제거할 수 있습니다.This gives the underlying TaskScheduler object the chance to add, change, or remove threads that service the loop.
추가 정보
적용 대상
ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource>)
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on an IEnumerable in which iterations may run in parallel and loop options can be configured.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Action<TSource> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Generic.IEnumerable<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Action<TSource> body);
static member ForEach : seq<'Source> * System.Threading.Tasks.ParallelOptions * Action<'Source> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As IEnumerable(Of TSource), parallelOptions As ParallelOptions, body As Action(Of TSource)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- body
- Action<TSource>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled
source
인수가 null
인 경우The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 현재 요소에 매개 변수로 제공 됩니다.It is provided with the current element as a parameter.
추가 정보
적용 대상
ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource,ParallelLoopState>)
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on an IEnumerable in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Action<TSource, System::Threading::Tasks::ParallelLoopState ^> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Generic.IEnumerable<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Action<TSource,System.Threading.Tasks.ParallelLoopState> body);
static member ForEach : seq<'Source> * System.Threading.Tasks.ParallelOptions * Action<'Source, System.Threading.Tasks.ParallelLoopState> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As IEnumerable(Of TSource), parallelOptions As ParallelOptions, body As Action(Of TSource, ParallelLoopState)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- body
- Action<TSource,ParallelLoopState>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled
source
인수가 null
인 경우The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 이 매개 변수는 현재 요소와 ParallelLoopState 루프를 중간에 중단 하는 데 사용할 수 있는 인스턴스와 같은 매개 변수를 제공 합니다.It is provided with the following parameters: the current element, and a ParallelLoopState instance that may be used to break out of the loop prematurely.
추가 정보
적용 대상
ForEach<TSource>(IEnumerable<TSource>, Action<TSource,ParallelLoopState>)
반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on an IEnumerable in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, Action<TSource, System::Threading::Tasks::ParallelLoopState ^> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Generic.IEnumerable<TSource> source, Action<TSource,System.Threading.Tasks.ParallelLoopState> body);
static member ForEach : seq<'Source> * Action<'Source, System.Threading.Tasks.ParallelLoopState> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As IEnumerable(Of TSource), body As Action(Of TSource, ParallelLoopState)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- body
- Action<TSource,ParallelLoopState>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 이 매개 변수는 현재 요소와 ParallelLoopState 루프를 중간에 중단 하는 데 사용할 수 있는 인스턴스와 같은 매개 변수를 제공 합니다.It is provided with the following parameters: the current element, and a ParallelLoopState instance that may be used to break out of the loop prematurely.
추가 정보
적용 대상
ForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource>)
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 Partitioner에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on a Partitioner in which iterations may run in parallel and loop options can be configured.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::Partitioner<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Action<TSource> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Concurrent.Partitioner<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Action<TSource> body);
static member ForEach : System.Collections.Concurrent.Partitioner<'Source> * System.Threading.Tasks.ParallelOptions * Action<'Source> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As Partitioner(Of TSource), parallelOptions As ParallelOptions, body As Action(Of TSource)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
매개 변수
- source
- Partitioner<TSource>
원래 데이터 소스가 포함된 Partitioner입니다.The partitioner that contains the original data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- body
- Action<TSource>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
source
인수가 null
인 경우The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
source
Partitioner의 SupportsDynamicPartitions 속성은 false
를 반환합니다.The SupportsDynamicPartitions property in the source
partitioner returns false
.
또는-or-
source
파티셔너에 있는 모든 메서드가 null
을 반환할 때 throw되는 예외입니다.The exception that is thrown when any methods in the source
partitioner return null
.
지정된 대리자 중 하나에서 throw된 예외가 포함되도록 throw되는 예외입니다.The exception that is thrown to contain an exception thrown from one of the specified delegates.
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. Parallel.ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The Parallel.ForEach method expects custom partitioners to support dynamic partitioning. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
추가 정보
적용 대상
ForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource,ParallelLoopState>)
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 Partitioner에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on a Partitioner in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::Partitioner<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Action<TSource, System::Threading::Tasks::ParallelLoopState ^> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Concurrent.Partitioner<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Action<TSource,System.Threading.Tasks.ParallelLoopState> body);
static member ForEach : System.Collections.Concurrent.Partitioner<'Source> * System.Threading.Tasks.ParallelOptions * Action<'Source, System.Threading.Tasks.ParallelLoopState> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As Partitioner(Of TSource), parallelOptions As ParallelOptions, body As Action(Of TSource, ParallelLoopState)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
매개 변수
- source
- Partitioner<TSource>
원래 데이터 소스가 포함된 Partitioner입니다.The partitioner that contains the original data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- body
- Action<TSource,ParallelLoopState>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프의 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
source
인수가 null
인 경우The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
source
Partitioner의 SupportsDynamicPartitions 속성은 false
를 반환합니다.The SupportsDynamicPartitions property in the source
partitioner returns false
.
또는-or-
source
파티셔너에 있는 모든 메서드가 null
을 반환할 때 throw되는 예외입니다.The exception that is thrown when any methods in the source
partitioner return null
.
지정된 대리자 중 하나에서 throw된 예외가 포함되도록 throw되는 예외입니다.The exception that is thrown to contain an exception thrown from one of the specified delegates.
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. Parallel.ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The Parallel.ForEach method expects custom partitioners to support dynamic partitioning. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
추가 정보
적용 대상
ForEach<TSource>(OrderablePartitioner<TSource>, ParallelOptions, Action<TSource,ParallelLoopState,Int64>)
반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 OrderablePartitioner<TSource>에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on a OrderablePartitioner<TSource> in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::OrderablePartitioner<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Action<TSource, System::Threading::Tasks::ParallelLoopState ^, long> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Concurrent.OrderablePartitioner<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Action<TSource,System.Threading.Tasks.ParallelLoopState,long> body);
static member ForEach : System.Collections.Concurrent.OrderablePartitioner<'Source> * System.Threading.Tasks.ParallelOptions * Action<'Source, System.Threading.Tasks.ParallelLoopState, int64> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As OrderablePartitioner(Of TSource), parallelOptions As ParallelOptions, body As Action(Of TSource, ParallelLoopState, Long)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
매개 변수
원래 데이터 소스가 포함된 정렬할 수 있는 파티셔너입니다.The orderable partitioner that contains the original data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- body
- Action<TSource,ParallelLoopState,Int64>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled
source
인수가 null
입니다.The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
source
에서 정렬할 수 있는 파티셔너의 SupportsDynamicPartitions 속성은 false
를 반환합니다.The SupportsDynamicPartitions property in the source
orderable partitioner returns false
.
또는-or-
source
에서 정렬할 수 있는 파티셔너의 KeysNormalized 속성은 false
를 반환합니다.The KeysNormalized property in the source
orderable partitioner returns false
.
또는-or-
source
정렬할 수 있는 파티셔너에 있는 모든 메서드가 null
을 반환할 때 throw되는 예외입니다.The exception that is thrown when any methods in the source
orderable partitioner return null
.
지정된 대리자 중 하나에서 throw된 예외가 포함되도록 throw되는 예외입니다.The exception that is thrown to contain an exception thrown from one of the specified delegates.
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. Parallel.ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The Parallel.ForEach method expects custom partitioners to support dynamic partitioning. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
추가 정보
적용 대상
ForEach<TSource>(IEnumerable<TSource>, Action<TSource>)
반복이 병렬로 실행될 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable 작업을 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on an IEnumerable in which iterations may run in parallel.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, Action<TSource> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Generic.IEnumerable<TSource> source, Action<TSource> body);
static member ForEach : seq<'Source> * Action<'Source> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As IEnumerable(Of TSource), body As Action(Of TSource)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- body
- Action<TSource>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
예제
다음 예제에서는 메서드를 사용 하 여 ForEach<TSource>(IEnumerable<TSource>, Action<TSource>) 텍스트 파일의 모음 및 공백이 아닌 문자 수를 계산 합니다.The following example uses the ForEach<TSource>(IEnumerable<TSource>, Action<TSource>) method to count the number of vowels and non-white-space characters in a text file. 이 경우 ParallelLoopResult 메서드에서 반환 된 값은 무시 됩니다.In this case, the ParallelLoopResult value returned by the method is ignored. 작업은 병렬로 실행할 수 있으므로 카운터 변수를 증가 시키는 것이 원자성 작업 이며 여러 스레드가 카운터 변수에 동시에 액세스를 시도 하지 않는지 확인 해야 합니다.Note that, because operations can run in parallel, you must ensure that incrementing the counter variables is an atomic operation, and that multiple threads do not attempt to access the counter variables simultaneously. 이러한 목적을 위해이 예제에서는 lock
문 (c #의 경우)과 SyncLock
문 (Visual Basic)을 사용 합니다.For this purpose, the example uses the lock
statement (in C#) and the SyncLock
statement (in Visual Basic).
using System;
using System.IO;
using System.Threading.Tasks;
public class Example
{
public static void Main()
{
Task<String> task = ReadCharacters(@".\CallOfTheWild.txt");
String text = task.Result;
int nVowels = 0;
int nNonWhiteSpace = 0;
Object obj = new Object();
ParallelLoopResult result = Parallel.ForEach(text,
(ch) => {
Char uCh = Char.ToUpper(ch);
if ("AEIOUY".IndexOf(uCh) >= 0) {
lock (obj) {
nVowels++;
}
}
if (! Char.IsWhiteSpace(uCh)) {
lock (obj) {
nNonWhiteSpace++;
}
}
} );
Console.WriteLine("Total characters: {0,10:N0}", text.Length);
Console.WriteLine("Total vowels: {0,10:N0}", nVowels);
Console.WriteLine("Total non-white-space: {0,10:N0}", nNonWhiteSpace);
}
private static async Task<String> ReadCharacters(String fn)
{
String text;
using (StreamReader sr = new StreamReader(fn)) {
text = await sr.ReadToEndAsync();
}
return text;
}
}
// The example displays output like the following:
// Total characters: 198,548
// Total vowels: 58,421
// Total non-white-space: 159,461
Imports System.IO
Imports System.Threading.Tasks
Module Example
Public Sub Main()
Dim task As Task(Of String) = ReadCharacters(".\CallOfTheWild.txt")
Dim text As String = task.Result
Dim nVowels As Integer = 0
Dim nNonWhiteSpace As Integer = 0
Dim obj As New Object()
Dim result As ParallelLoopResult = Parallel.ForEach(text,
Sub(ch)
Dim uCh As Char = Char.ToUpper(ch)
If "AEIOUY".IndexOf(uCh) >= 0 Then
SyncLock obj
nVowels += 1
End SyncLock
End If
If Not Char.IsWhiteSpace(uCh) Then
SyncLock obj
nNonWhiteSpace += 1
End SyncLock
End If
End Sub)
Console.WriteLine("Total characters: {0,10:N0}", text.Length)
Console.WriteLine("Total vowels: {0,10:N0}", nVowels)
Console.WriteLine("Total non-white space: {0,10:N0}", nNonWhiteSpace)
End Sub
Private Async Function ReadCharacters(fn As String) As Task(Of String)
Dim text As String
Using sr As New StreamReader(fn)
text = Await sr.ReadToEndAsync()
End Using
Return text
End Function
End Module
' The output from the example resembles the following:
' Total characters: 198,548
' Total vowels: 58,421
' Total non-white space: 159,461
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 현재 요소에 매개 변수로 제공 됩니다.It is provided with the current element as a parameter.
추가 정보
적용 대상
ForEach<TSource>(IEnumerable<TSource>, Action<TSource,ParallelLoopState,Int64>)
64비트 인덱스를 사용하여 반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with 64-bit indexes on an IEnumerable in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, Action<TSource, System::Threading::Tasks::ParallelLoopState ^, long> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Generic.IEnumerable<TSource> source, Action<TSource,System.Threading.Tasks.ParallelLoopState,long> body);
static member ForEach : seq<'Source> * Action<'Source, System.Threading.Tasks.ParallelLoopState, int64> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As IEnumerable(Of TSource), body As Action(Of TSource, ParallelLoopState, Long)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- body
- Action<TSource,ParallelLoopState,Int64>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 이 매개 변수는 현재 요소, ParallelLoopState 외부에서 루프를 중단 하는 데 사용할 수 있는 인스턴스 및 현재 요소의 인덱스 ()와 함께 제공 됩니다. Int64It is provided with the following parameters: the current element, a ParallelLoopState instance that may be used to break out of the loop prematurely, and the current element's index (Int64).
추가 정보
적용 대상
ForEach<TSource>(Partitioner<TSource>, Action<TSource>)
반복이 병렬로 실행될 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 Partitioner 작업을 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on a Partitioner in which iterations may run in parallel.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::Partitioner<TSource> ^ source, Action<TSource> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Concurrent.Partitioner<TSource> source, Action<TSource> body);
static member ForEach : System.Collections.Concurrent.Partitioner<'Source> * Action<'Source> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As Partitioner(Of TSource), body As Action(Of TSource)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
매개 변수
- source
- Partitioner<TSource>
원래 데이터 소스가 포함된 Partitioner입니다.The partitioner that contains the original data source.
- body
- Action<TSource>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
입니다.The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
source
Partitioner의 SupportsDynamicPartitions 속성은 false
를 반환합니다.The SupportsDynamicPartitions property in the source
partitioner returns false
.
또는-or-
source
파티셔너에 있는 모든 메서드가 null
을 반환할 때 throw되는 예외입니다.The exception that is thrown when any methods in the source
partitioner return null
.
또는-or-
source
Partitioner의 GetPartitions(Int32) 메서드가 올바른 파티션 수를 반환하지 않습니다.The GetPartitions(Int32) method in the source
partitioner does not return the correct number of partitions.
지정된 대리자 중 하나에서 throw된 예외가 포함되도록 throw되는 예외입니다.The exception that is thrown to contain an exception thrown from one of the specified delegates.
예제
다음 예제에서는와 함께 사용할 범위 파티 셔 너를 구현 하는 방법을 보여 줍니다 Parallel.ForEach .The following example shows how to implement a range partitioner for use with Parallel.ForEach:
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
class RangePartitionerDemo
{
static void Main()
{
Stopwatch sw = null;
long sum = 0;
long SUMTOP = 10000000;
// Try sequential for
sw = Stopwatch.StartNew();
for (long i = 0; i < SUMTOP; i++) sum += i;
sw.Stop();
Console.WriteLine("sequential for result = {0}, time = {1} ms", sum, sw.ElapsedMilliseconds);
// Try parallel for -- this is slow!
//sum = 0;
//sw = Stopwatch.StartNew();
//Parallel.For(0L, SUMTOP, (item) => Interlocked.Add(ref sum, item));
//sw.Stop();
//Console.WriteLine("parallel for result = {0}, time = {1} ms", sum, sw.ElapsedMilliseconds);
// Try parallel for with locals
sum = 0;
sw = Stopwatch.StartNew();
Parallel.For(0L, SUMTOP, () => 0L, (item, state, prevLocal) => prevLocal + item, local => Interlocked.Add(ref sum, local));
sw.Stop();
Console.WriteLine("parallel for w/locals result = {0}, time = {1} ms", sum, sw.ElapsedMilliseconds);
// Try range partitioner
sum = 0;
sw = Stopwatch.StartNew();
Parallel.ForEach(Partitioner.Create(0L, SUMTOP), (range) =>
{
long local = 0;
for (long i = range.Item1; i < range.Item2; i++) local += i;
Interlocked.Add(ref sum, local);
});
sw.Stop();
Console.WriteLine("range partitioner result = {0}, time = {1} ms", sum, sw.ElapsedMilliseconds);
}
}
Imports System.Collections.Concurrent
Imports System.Threading
Imports System.Threading.Tasks
Module RangePartitionerDemo
Sub Main()
Dim sw As Stopwatch = Nothing
Dim sum As Long = 0
Dim SUMTOP As Long = 10000000
' Try sequential for
sw = Stopwatch.StartNew()
For i As Long = 0 To SUMTOP - 1
sum += i
Next
sw.Stop()
Console.WriteLine("sequential for result = {0}, time = {1} ms", sum, sw.ElapsedMilliseconds)
' Try parallel for with locals
sum = 0
sw = Stopwatch.StartNew()
Parallel.For(0L, SUMTOP, Function() 0L, Function(item, state, prevLocal) prevLocal + item, Function(local) Interlocked.Add(sum, local))
sw.Stop()
Console.WriteLine("parallel for w/locals result = {0}, time = {1} ms", sum, sw.ElapsedMilliseconds)
' Try range partitioner
sum = 0
sw = Stopwatch.StartNew()
Parallel.ForEach(Partitioner.Create(0L, SUMTOP),
Sub(range)
Dim local As Long = 0
For i As Long = range.Item1 To range.Item2 - 1
local += i
Next
Interlocked.Add(sum, local)
End Sub)
sw.Stop()
Console.WriteLine("range partitioner result = {0}, time = {1} ms", sum, sw.ElapsedMilliseconds)
End Sub
End Module
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. Parallel.ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The Parallel.ForEach method expects custom partitioners to support dynamic partitioning. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
추가 정보
적용 대상
ForEach<TSource>(Partitioner<TSource>, Action<TSource,ParallelLoopState>)
반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 Partitioner에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on a Partitioner in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::Partitioner<TSource> ^ source, Action<TSource, System::Threading::Tasks::ParallelLoopState ^> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Concurrent.Partitioner<TSource> source, Action<TSource,System.Threading.Tasks.ParallelLoopState> body);
static member ForEach : System.Collections.Concurrent.Partitioner<'Source> * Action<'Source, System.Threading.Tasks.ParallelLoopState> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As Partitioner(Of TSource), body As Action(Of TSource, ParallelLoopState)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
매개 변수
- source
- Partitioner<TSource>
원래 데이터 소스가 포함된 Partitioner입니다.The partitioner that contains the original data source.
- body
- Action<TSource,ParallelLoopState>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
source
Partitioner의 SupportsDynamicPartitions 속성은 false
를 반환합니다.The SupportsDynamicPartitions property in the source
partitioner returns false
.
또는-or-
source
Partitioner의 메서드는 null
를 반환합니다.A method in the source
partitioner returns null
.
또는-or-
source
Partitioner의 GetPartitions(Int32) 메서드가 올바른 파티션 수를 반환하지 않습니다.The GetPartitions(Int32) method in the source
partitioner does not return the correct number of partitions.
지정된 대리자 중 하나에서 throw된 예외가 포함되도록 throw되는 예외입니다.The exception that is thrown to contain an exception thrown from one of the specified delegates.
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. Parallel.ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The Parallel.ForEach method expects custom partitioners to support dynamic partitioning. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
추가 정보
적용 대상
ForEach<TSource>(OrderablePartitioner<TSource>, Action<TSource,ParallelLoopState,Int64>)
반복을 병렬로 실행할 수 있고 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 OrderablePartitioner<TSource>에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation on a OrderablePartitioner<TSource> in which iterations may run in parallel and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Concurrent::OrderablePartitioner<TSource> ^ source, Action<TSource, System::Threading::Tasks::ParallelLoopState ^, long> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Concurrent.OrderablePartitioner<TSource> source, Action<TSource,System.Threading.Tasks.ParallelLoopState,long> body);
static member ForEach : System.Collections.Concurrent.OrderablePartitioner<'Source> * Action<'Source, System.Threading.Tasks.ParallelLoopState, int64> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As OrderablePartitioner(Of TSource), body As Action(Of TSource, ParallelLoopState, Long)) As ParallelLoopResult
형식 매개 변수
- TSource
source
의 요소 형식입니다.The type of the elements in source
.
매개 변수
원래 데이터 소스가 포함된 정렬할 수 있는 파티셔너입니다.The orderable partitioner that contains the original data source.
- body
- Action<TSource,ParallelLoopState,Int64>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
source
인수가 null
인 경우The source
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
source
에서 정렬할 수 있는 파티셔너의 SupportsDynamicPartitions 속성은 false
를 반환합니다.The SupportsDynamicPartitions property in the source
orderable partitioner returns false
.
또는-or-
소스에서 정렬할 수 있는 파티셔너의 KeysNormalized 속성은 false
를 반환합니다.The KeysNormalized property in the source orderable partitioner returns false
.
또는-or-
소스 정렬 가능 파티셔너의 모든 메서드는 null
을 반환합니다.Any methods in the source orderable partitioner return null
.
지정된 대리자 중 하나에서 throw된 예외입니다.The exception thrown from one of the specified delegates.
설명
이 오버 로드는 기본 파티션 구성표를 재정의 하려는 시나리오에 대해 제공 됩니다.This overload is provided for scenarios where you want to override the default partitioning scheme. 예를 들어 작은 루프 본문은 범위를 분할 하는 이점을 누릴 수 있습니다.For example, small loop bodies might benefit from partitioning the range. Parallel.ForEach메서드에는 동적 분할을 지원 하기 위해 사용자 지정 파티 셔 너가 필요 합니다.The Parallel.ForEach method expects custom partitioners to support dynamic partitioning. 자세한 내용은 PLINQ 및 TPL에 대 한 사용자 지정 파티 셔 너 및 방법: 동적 파티션 구현을 참조 하세요.For more information, see Custom Partitioners for PLINQ and TPL and How to: Implement Dynamic Partitions.
추가 정보
적용 대상
ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource,ParallelLoopState,Int64>)
64비트 인덱스를 사용하여 반복을 병렬로 실행할 수 있고 루프 옵션을 구성할 수 있으며 루프 상태를 모니터링 및 조작할 수 있는 foreach
(Visual Basic의 경우 For Each
) 작업을 IEnumerable에 대해 실행합니다.Executes a foreach
(For Each
in Visual Basic) operation with 64-bit indexes on an IEnumerable in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
public:
generic <typename TSource>
static System::Threading::Tasks::ParallelLoopResult ForEach(System::Collections::Generic::IEnumerable<TSource> ^ source, System::Threading::Tasks::ParallelOptions ^ parallelOptions, Action<TSource, System::Threading::Tasks::ParallelLoopState ^, long> ^ body);
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource> (System.Collections.Generic.IEnumerable<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, Action<TSource,System.Threading.Tasks.ParallelLoopState,long> body);
static member ForEach : seq<'Source> * System.Threading.Tasks.ParallelOptions * Action<'Source, System.Threading.Tasks.ParallelLoopState, int64> -> System.Threading.Tasks.ParallelLoopResult
Public Shared Function ForEach(Of TSource) (source As IEnumerable(Of TSource), parallelOptions As ParallelOptions, body As Action(Of TSource, ParallelLoopState, Long)) As ParallelLoopResult
형식 매개 변수
- TSource
소스의 데이터 형식입니다.The type of the data in the source.
매개 변수
- source
- IEnumerable<TSource>
열거 가능한 데이터 소스입니다.An enumerable data source.
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.An object that configures the behavior of this operation.
- body
- Action<TSource,ParallelLoopState,Int64>
반복당 한 번씩 호출되는 대리자입니다.The delegate that is invoked once per iteration.
반환
완료된 루프 부분에 대한 정보가 포함된 구조체입니다.A structure that contains information about which portion of the loop completed.
예외
parallelOptions
인수의 CancellationToken이 취소된 경우The CancellationToken in the parallelOptions
argument is canceled
source
인수가 null
인 경우The source
argument is null
.
또는-or-
parallelOptions
인수가 null
인 경우The parallelOptions
argument is null
.
또는-or-
body
인수가 null
인 경우The body
argument is null
.
모든 개별 예외를 포함하는 예외는 스레드에서 throw됩니다.The exception that contains all the individual exceptions thrown on all threads.
parallelOptions
의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.The CancellationTokenSource associated with the CancellationToken in the parallelOptions
has been disposed.
설명
body
대리자는 열거 가능한의 각 요소에 대해 한 번씩 호출 됩니다 source
.The body
delegate is invoked once for each element in the source
enumerable. 이 매개 변수는 현재 요소, ParallelLoopState 외부에서 루프를 중단 하는 데 사용할 수 있는 인스턴스 및 현재 요소의 인덱스 ()와 함께 제공 됩니다. Int64It is provided with the following parameters: the current element, a ParallelLoopState instance that may be used to break out of the loop prematurely, and the current element's index (Int64).