-
Notifications
You must be signed in to change notification settings - Fork 4
/
Update-WPFJob.ps1
52 lines (47 loc) · 2.91 KB
/
Update-WPFJob.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Update-WPFJob
{
<#
.Synopsis
Updates a running WPF Job by running a PowerShell script
.Description
Runs a PowerShell script within a WPF Job and returns the results.
This enables two way communication with WPF Jobs.
You can use the $Window variable and Get-ChildControl to talk to
individual controls within a UI.
.Example
$Job = New-Label "Hello World" -AsJob
$job | Update-WPFJob { $window.Close() }
#>
[CmdletBinding(DefaultParameterSetName='NoParameters')]
param(
# The Job to update
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[Management.Automation.Job]
$Job,
[Parameter(Position=0)]
[ScriptBlock]
$Command,
[Parameter(ParameterSetName='IDictionary', Position=1)]
[Collections.IDictionary]
$Dictionary,
[Parameter(ParameterSetName='IList', Position=1)]
[Collections.IList]
$List
)
process {
if ($job.InvokeScriptInJob) {
switch ($psCmdlet.ParameterSetName) {
NoParameters {
$job.InvokeScriptInJob($Command, $null)
}
List {
$job.InvokeScriptInJob($command, $List)
}
Dictionary {
$job.InvokeScriptInJob($Command, $Dictionary)
}
}
}
}
}