PowerShell工作流程 - 初始延迟

时间:2017-06-13 17:57:30

标签: powershell xaml workflow-foundation

首次在新PS流程中运行PowerShell工作流时,PS工作流转换为XAML时会出现初始延迟。后续运行的工作流程不会遇到相同的初始化延迟。

示例:

workflow Test-CompilationTime { Write-Output "We ran!" }

首次运行:

Measure-Command {Test-CompilationTime}

Days : 0 Hours : 0 Minutes : 0 Seconds : 0 Milliseconds : 636

后续运行:

Measure-Command {Test-CompilationTime}

Days : 0 Hours : 0 Minutes : 0 Seconds : 0 Milliseconds : 64

我已尝试导出XAML定义并尝试将其放入PS模块中,几乎没有成功。

(Get-Command Test-CompilationTime).XamlDefinition

<Activity
x:Class="Microsoft.PowerShell.DynamicActivities.Activity_105873347"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"
xmlns:local="clr-namespace:Microsoft.PowerShell.DynamicActivities"
xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ns0="clr-namespace:System;assembly=mscorlib"
xmlns:ns1="clr-namespace:Microsoft.PowerShell.Activities;assembly=Microsoft.PowerShell.Activities"
xmlns:ns2="clr-namespace:System.Activities;assembly=System.Activities"
xmlns:ns3="clr-namespace:Microsoft.PowerShell.Utility.Activities;assembly=Microsoft.PowerShell.Utility.Activities"
xmlns:ns4="clr-namespace:System.Management.Automation;assembly=System.Management.Automation"
>
<Sequence>
    <ns1:SetPSWorkflowData>
        <ns1:SetPSWorkflowData.OtherVariableName>Position</ns1:SetPSWorkflowData.OtherVariableName>
        <ns1:SetPSWorkflowData.Value>
            <ns2:InArgument x:TypeArguments="ns0:Object">
                <ns1:PowerShellValue x:TypeArguments="ns0:Object" Expression="'2:5:Test-CompilationTime'" />
            </ns2:InArgument>
        </ns1:SetPSWorkflowData.Value>
    </ns1:SetPSWorkflowData>
    <ns3:WriteOutput>
        <ns3:WriteOutput.InputObject>
            <ns2:InArgument x:TypeArguments="ns4:PSObject[]">
                <ns1:PowerShellValue x:TypeArguments="ns4:PSObject[]" Expression="&quot;We ran!&quot;" />
            </ns2:InArgument>
        </ns3:WriteOutput.InputObject>
    </ns3:WriteOutput>
    <Sequence.Variables>
        <Variable Name="WorkflowCommandName" x:TypeArguments="ns0:String" Default = "Test-CompilationTime" />
    </Sequence.Variables>
</Sequence>

如何编写PS工作流程,以便它可以包含在PS模块(.psm1)中,而不会体验工作流程 - &gt; XAML延迟?

0 个答案:

没有答案