Hallo Zusammen,
ist es möglich, innerhalb eines laufenden Timers, eine While Schleife einzubauen die jede Sekunde eine Process Prüfung macht,
und wenn der Process läuft, das Formular den Times stoppt und das Formular schließt?
Hier mal mein Code für das Form.
function GoogleForm
{
#Create a form
$GoogleForm.SelectNodes("//*[@Name]") | ForEach-Object {Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
$XMLReader = (New-Object System.Xml.XmlNodeReader $GoogleForm)
$Form = [Windows.Markup.XamlReader]::Load($XMLReader)
#Connect to Controls
$TimeBox = $Form.FindName('TimeBox')
#Event handlers
$Form.Add_SourceInitialized({
$script:seconds = new-timespan -minute 1 -Seconds 0
$script:timer = new-object System.Windows.Threading.DispatcherTimer
$timer.Interval = [TimeSpan]'0:0:1.0'
$timer.Add_Tick.Invoke(
$UpDateBlock)
$timer.Start()
if ($timer.IsEnabled -eq $false) {
write-warning "Timer didn't start"
}
})
$UpDateBlock = ({
$script:seconds= $script:seconds.Subtract('0:0:1')
$Timebox.text=($seconds.ToString('mm\:ss')
)
if($seconds -eq 0)
{taskkill /F /IM chrome.exe /T | Out-Null
$Form.Close()
}
})
#B_Reboot Button
$B_Reboot = $Form.FindName('Edge')
$B_Reboot.add_click({
write-host test
$Form.Close()
})
# Position auf Bildschirm begrenzen
$Form.add_LocationChanged(
{
if ($this.Left -lt 0){$this.Left = 0}
if ($this.Top -lt 0){$this.Top = 0}
if ($this.Top + $this.Height -gt $Screen.Height){$this.Top = $Screen.Height - $this.Height}
if ($this.Left + $this.Width -gt $Screen.Width){$this.Left = $Screen.Width - $this.Width}
})
# Show
#$Form.Add_Closing({$_.cancel = $true}) #Close Button deaktivieren
$Form.ShowDialog()
}Ich bin um jeden Tipp sehr dankbar.
Liebe Grüße
gfritz74







