Scripts/WindowsTimer

From J Wiki
Jump to: navigation, search

I have tested this on win7 with J602 and J701 jconsole.

NB. Timer test

NB. timer'' sets a timer for 10 seconds from now.
NB. cdcallback gets control when the timer goes off.
NB. dtq'' should be run when you are done with the timer.
NB. timert'' sets the timer to trigger ever .1 second until dtq'' is run.

require 'dll'

CreateTimerQueueTimer=: >@{.@('kernel32 CreateTimerQueueTimer i *x x x *x i i i'&(15!:0))
CreateTimerQueue=: >@{.@('kernel32 CreateTimerQueue i'&(15!:0))
DeleteTimerQueueEx=: >@{.@('kernel32 DeleteTimerQueueEx i x x'&(15!:0))

timercb=: cdcb 2

timercount=: 0

cdcallback=: 3 : 0
cdresult=:y
timer_popped=: 6!:0 ''
timercount=:>:timercount
)

timer=: 3 : 0
nt=.,2-2
timerq=:CreateTimerQueue''
CreateTimerQueueTimer nt;timerq;timercb;(,2-2);10000;0;0
timer_set=:6!:0''
)

timert=: 3 : 0
nt=.,2-2
timerq=:CreateTimerQueue''
CreateTimerQueueTimer nt;timerq;timercb;(,2-2);100;100;0
timer_set=:6!:0''
)

dtq=: 3 : 0
DeleteTimerQueueEx timerq;2-2
)