My script stops when I´m calling the message box or the voice output.
The script is waiting to complete the task what is the normal behavior in PowerShell.
But how it is possible to execute this script without a break at the voice output?
I want to execute this code without a break:
[System.Windows.Forms.MessageBox]::Show("stop")
$voice = new-object -com SAPI.SpVoice
$voice.Speak("Hello Stackoverflow!")
[System.Windows.Forms.MessageBox]::Show("done")
Like (Not working):
[System.Windows.Forms.MessageBox]::Show("stop")
$job = start-job {
$voice = new-object -com SAPI.SpVoice
$voice.Speak($text)
}
[System.Windows.Forms.MessageBox]::Show("done")
or like (Also not working):
$test = "Hello"
[System.Windows.Forms.MessageBox]::Show("stop")
$backPS = [powershell]::create()
[void] $backPS.AddScript("$voice = new-object -com SAPI.SpVoice
$voice.Speak($test)")
[System.Windows.Forms.MessageBox]::Show("done")
The background job approach works for me:
$textneeds to either be passed to the background job or defined in the background job script block.The other blocking code is
[System.Windows.Forms.MessageBox]::Show. Do you want this to be synchronous or asynchronous?