Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/System.Management.Automation/engine/InternalCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ public object[] ArgumentList
[Parameter(ParameterSetName = ForEachObjectCommand.ParallelParameterSet)]
public SwitchParameter AsJob { get; set; }

/// <summary>
/// Gets or sets a flag so that a new runspace object is created for each loop iteration, instead of reusing objects
/// from the runspace pool.
/// By default, runspaces are reused from a runspace pool.
/// </summary>
[Parameter(ParameterSetName = ForEachObjectCommand.ParallelParameterSet)]
public SwitchParameter UseNewRunspace { get; set; }

#endregion

#region Overrides
Expand Down Expand Up @@ -437,15 +445,16 @@ private void InitParallelParameterSet()

_taskJob = new PSTaskJob(
Parallel.ToString(),
ThrottleLimit);
ThrottleLimit,
UseNewRunspace);

return;
}

// Set up for synchronous processing and data streaming.
_taskCollection = new PSDataCollection<System.Management.Automation.PSTasks.PSTask>();
_taskDataStreamWriter = new PSTaskDataStreamWriter(this);
_taskPool = new PSTaskPool(ThrottleLimit);
_taskPool = new PSTaskPool(ThrottleLimit, UseNewRunspace);
_taskPool.PoolComplete += (sender, args) =>
{
_taskDataStreamWriter.Close();
Expand Down
Loading