src/Microsoft.PowerShell.Activities/Activities/ThrottledParallelForeach.cs
/// <summary>
/// Invoke the activity's actions
/// </summary>
/// <param name="context"></param>
Invoke the activity's actions
Invoke the activity ' s actions
protected override void Execute(NativeActivityContext context)
        {
            IEnumerable<T> values = this.Values.Get(context);
            if (values == null)
            {
                throw new ApplicationException("ParallelForEach requires a non null Values collection");
            }
            this.valueEnumerator.Set(context, values.GetEnumerator());
            int max = this.ThrottleLimit.Get(context);
            if (max < 1) max = int.MaxValue;
            int runningCount = 0;
            this.hasCompleted.Set(context, false);
            onBodyComplete = new CompletionCallback(OnBodyComplete);
            while (runningCount < max && valueEnumerator.Get(context).MoveNext())
            {
                runningCount++;
                if (this.Body != null)
                {
                    context.ScheduleAction(this.Body, valueEnumerator.Get(context).Current, onBodyComplete);
                }
            }
        }
protected override void Execute ( NativeActivityContext context ) { IEnumerable < T > values = this . Values . Get ( context ) ; if ( values == null ) { throw new ApplicationException ( " " ) ; } this . valueEnumerator . Set ( context , values . GetEnumerator ( ) ) ; int max = this . ThrottleLimit . Get ( context ) ; if ( max < 1 ) max = int . MaxValue ; int runningCount = 0 ; this . hasCompleted . Set ( context , false ) ; onBodyComplete = new CompletionCallback ( OnBodyComplete ) ; while ( runningCount < max && valueEnumerator . Get ( context ) . MoveNext ( ) ) { runningCount ++ ; if ( this . Body != null ) { context . ScheduleAction ( this . Body , valueEnumerator . Get ( context ) . Current , onBodyComplete ) ; } } }
Invoke the activity's actions
Invoke the activity ' s actions
// get the list of value to iterate through // get the enumerator             // initialize the values for creating the execution window (max and runningCount) // initialize the value of the completion variable // cache the completion callback // iterate while there are items available and we didn't exceed the throttle factor // increase the running instances counter
context
NativeActivityContext
None