I'm working on Powershell GUI which show to an user, each step for establish a connection to a VPN. So when he start the script, he will see all's steps, with the current step in bold and the last completed step in light gray. A Webbrowser is here to show additionnal info by loading html file related to the current step.
I don't understand how I must load my GUI on one hand, and do my backgrounds jobs on the other hand. In this exemple, it's working because I have created a button event for change the html :
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$SyncHash = [hashtable]::Synchronized(@{})
$Main = New-Object Windows.Forms.Form
$Main.Width = 768
$Main.Height = 576
$button_1 = New-Object System.Windows.Forms.Button
$button_1.Text = "1"
$button_1.Size = New-Object System.Drawing.Size(20,20)
$button_1.Location = New-Object System.Drawing.Size(20,10)
$Main.Controls.Add($button_1)
$SyncHash.infoBrowser = new-object Windows.Forms.WebBrowser
$SyncHash.infoBrowser.Size = new-object System.Drawing.Size(710,200)
$SyncHash.infoBrowser.Location = new-object System.Drawing.Size(10,290)
$SyncHash.infoBrowser.ScrollBarsEnabled = $true
$Main.Controls.Add($SyncHash.infoBrowser)
$htmlFile = "h:\csv\Test.html"
$html = get-content $htmlFile
$SyncHash.infoBrowser.DocumentText = $html
$button_1.Add_Click(
{
$htmlFile = "h:\csv\underLAN.html"
$html = get-content $htmlFile
write-host $html
$SyncHash.infoBrowser.DocumentText = $html
})
[Windows.Forms.Application]::Run($Main)
But, if try to use a job, nothings happens.
...
$underLAN={
$htmlFile = "h:\csv\underLAN.html"
$html = get-content $htmlFile
write-host $html
$SyncHash.infoBrowser.DocumentText = $html
}
[Windows.Forms.Application]::Run($Main)
Start-Job -Name test -ScriptBlock $underLAN | Receive-Job