$swCtrlC is a stopwatch, $script:cntCtrlC is a counter. I've moved the code from the function to the main loop. UPDATE - still having problems with this. Why does this function take so long to execute, and is there a better (i.e. Since the script checks for ctrl+c almost continuously, this has a big performance hit on the overall script. The code works fine, but whilst doing some performance tuning I've discovered that this takes around 100ms every time it's called. If ($Host.UI.RawUI.KeyAvailable -and (3 -eq $Host.UI.RawUI.ReadKey("AllowCtrlC,IncludeKeyUp,NoEcho").Character)) # Stops Ctrl+C from exiting this function I use this simple function to check if the ctrl+c keys have been pressed function fnTestForCtrlC I have a powerShell script that runs 24x7 until a user presses crtl+c to perform a controlled shutdown.
0 Comments
Leave a Reply. |