Advertisement
easternnl

Timeout in a while loop & WASP

Nov 27th, 2015
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Module C:\Users\erik\Documents\WASP\WASP.dll
  2.  
  3. try
  4. {
  5.  
  6.     $timeout = new-timespan -Seconds 5
  7.     $sw = [diagnostics.stopwatch]::StartNew()
  8.  
  9.     # Wait until the program is started
  10.     while ((Select-Window -ProcessName NOTEPAD) -eq $null)
  11.     {
  12.         Write-Progress "Waiting for NOTEPAD"
  13.  
  14.         if ($sw.elapsed -gt $timeout)
  15.         {
  16.             throw "time out"
  17.         }
  18.     }
  19.  
  20.     Write-Host "Notepad detected"
  21. }
  22. catch
  23. {
  24.     Write-Host "ERROR: $($Error[0].Exception)"
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement