Events: Difference between revisions

757 bytes added ,  7 years ago
no edit summary
(→‎{{header|Elixir}}: uses Time module)
No edit summary
Line 827:
(prinl "Exit in 4 seconds")
(alarm 4 (bye)) )</lang>
 
=={{header|PowerShell}}==
<lang PowerShell>
$timer = New-Object -TypeName System.Timers.Timer -Property @{Enabled=$true; Interval=1000; AutoReset=$true}
 
$action = {
$global:counter += 1
Write-Host “Event counter is ${counter}: $((Get-Date).ToString("hh:mm:ss"))”
if ($counter -ge $event.MessageData)
{
Write-Host “Timer stopped”
$timer.Stop()
}
}
 
$job = Register-ObjectEvent -InputObject $timer -MessageData 5 -SourceIdentifier Count -EventName Elapsed -Action $action
 
$global:counter = 0
& $job.Module {$global:counter}
</lang>
{{Out}}
<pre>
Event counter is 1: 04:58:04
Event counter is 2: 04:58:05
Event counter is 3: 04:58:06
Event counter is 4: 04:58:07
Event counter is 5: 04:58:08
Timer stopped
</pre>
 
=={{header|PureBasic}}==
308

edits