2016-06-29 4 views
1

PowerShellでRunspace Poolを使用して、バックグラウンドアクションを実行したかったのです。しかし、私はメインスレッドからWPFウィンドウ変数にアクセスする必要があります。RunStatusプールを持つSessionStateProxy変数

通常の実行空間は、オプションがあります:

$runspace.SessionStateProxy.SetVariable('xamGUI',$xamGUI) 

をしかし、私はRunspacePoolと同じことをどのように行うのですか?

答えて

2

runspacepoolに変数を追加するのはもう少し複雑ですが、やはり間違いなく実行可能です。 InitialSessionStateオブジェクトを作成し、runspacepoolに追加する変数を含むSessionStateVariableEntryオブジェクトを作成する必要があります。

[int]$Test = 123498765 
#Create the sessionstate variable entry 
$Variable = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'Test',$Test,$Null 
$InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault() 

#Add the variable to the sessionstate 
$InitialSessionState.Variables.Add($Variable) 

#Create the runspacepool using the defined sessionstate variable 
$RunspacePool = [runspacefactory]::CreateRunspacePool(1,$Throttle,$InitialSessionState,$Host) 
関連する問題