我想对我的一个脚本实施-parallel Switch
非并行版本:
$tmpArray | ForEach-Object {
#region ... local Variables
$stepWidthLocal = $stepWidth
<#
my code
#>
并行功能:
$tmpArray | ForEach-Object -ThrottleLimit ($parallelBlocks * 10) -Parallel {
#region ... local Variables
$stepWidthLocal = $using:stepWidth
<#
my code
#>
我不想要的是:
$myParallel = $true
if ($myParallel) {
$tmpArray | ForEach-Object -ThrottleLimit ($parallelBlocks * 10) -Parallel {
#region ... local Variables
$stepWidthLocal = $using:stepWidth
<#
my code
#>
} #end $tmpArray | ForEach-Object -ThrottleLimit ($parallelBlocks * 10) -Parallel
} #end if($myParallel)
else {
$tmpArray | ForEach-Object {
#region ... local Variables
$stepWidthLocal = $stepWidth
<#
my code
#>
} #end $tmpArray | ForEach-Object {
} #end else {
我想要这样的东西:
$myCode = <#
define my Codeblock
#>
$myParallel = $true
if ($myParallel) {
$tmpArray | ForEach-Object -ThrottleLimit ($parallelBlocks * 10) -Parallel {
#region ... local Variables
$stepWidthLocal = $using:stepWidth
$myCode
} #end $tmpArray | ForEach-Object -ThrottleLimit ($parallelBlocks * 10) -Parallel
} #end if($myParallel)
else {
$tmpArray | ForEach-Object {
#region ... local Variables
$stepWidthLocal = $stepWidth
$myCode
} #end $tmpArray | ForEach-Object {
} #end else {
现在我想创建某种 switch 语句而不复制整个代码(块 <# my code#>)。
这可能吗?