Handle a signal: Difference between revisions

(→‎{{header|F#}}: added F#)
(→‎{{header|PureBasic}}: Added PureBasic)
Line 373:
end handler;
</lang>
=={{header|PureBasic}}==
This code is for Windows only due to the usage of SetConsoleCtrlHandler()
<lang PureBasic>CompilerIf #PB_Compiler_OS<>#PB_OS_Windows
CompilerError "This code is Windows only"
CompilerEndIf
 
Global Quit, i, T0=ElapsedMilliseconds(), T1
 
Procedure CtrlC()
T1=ElapsedMilliseconds()
Quit=1
While i: Delay(1): Wend
EndProcedure
 
If OpenConsole()
SetConsoleCtrlHandler_(@CtrlC(),#True)
While Not Quit
PrintN(Str(i))
i+1
Delay(500)
Wend
PrintN("Program has run for "+StrF((T1-T0)/1000,3)+" seconds.")
Print ("Press ENTER to exit."):Input(): i=0
EndIf</lang>
<pre>0
1
2
3
4
Program has run for 2.121 seconds.
Press ENTER to exit.</pre>
 
=={{header|Python}}==
Anonymous user