I am trying to put a time limit for an input box before which it closes.
I have used the if command and end-date such that:
$endDate = (Get-Date).AddSeconds(10)
while ((Get-Date) -lt $endDate) {
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$Choice = $objTextBox.SelectedItem.ToString(); $objForm.Close()}})
$objForm.Topmost = $True
if ((Get-Date) -ge $Fate) { $objForm.Invoke( }
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
}
if ((Get-Date) -ge $endDate) { #whatever Function Here}
it seems that the input box stops all the actions of the script. I have tried to time the second function (the one starting with if) inside the same function without using the while loop but it didn't work.
Any Ideas?