As the title says, I have two processes I would like to run and wait until both are completed.
I'm trying to create a powershell function that will invoke a rest api as well as call an exe that will display a dialog.
function SaySpeechWithPrompt($message, $timeout, $promptTitle="") {
$job1 = {
param($messageArg)
Invoke-RestMethod "http://localhost:9090/api/saySpeech?message=$messageArg" -Method Get
}
$job2 = {
param($promptTitleArg, $messageArg, $timeoutArg)
.\Dialog\Dialog.exe $promptTitleArg $messageArg 6 $timeoutArg
}
Start-Job -ScriptBlock $job1 -ArgumentList $message
Start-Job -ScriptBlock $job2 -ArgumentList $promptTitle, $message, $timeout
While (Get-Job -State "Running")
{
Start-Sleep 1
}
}
This is what I have so far. Doesn't work well. Few problems
- The dialog is never displayed, seems like running this in a scriptblock is causing issues.
- I'm not sure that the above will call both processes and wait for both to finish. I.e is Get-Job just checking the last job? I need it to check both jobs.
- Is there a better way of doing this without sleeping in a loop?
I'm very new to powershell!