.net - Handling multipe timers in a single timer -


i have around 20 timers on form, different intervals. example, 1 has interval of 25, 1 has interval of 100, have "irregular" intervals 43.

i have single timer , handle in tick event.

for example this:

private sub _tmrall_tick(sender object, e eventargs) handles _tmrall.tick      _itimer += 25      if _itimer mod 25 = 0         phandleclickdelayrepeat()     end if      if _itimer mod 100 = 0         phandleskype()     end if      if _itimer mod 43 = 0 'this of course not work current approach         phandlemouse()     end if 

it think current approach not because can not handle these irregular intervals.

does have better idea of how it?

thank you.

you need 1 timer , set interval largest divisor (with no remainder) of of intervals can.

in case 43 divides 43 or 1. can't use 43 because not divisor of 25, option 1. means firing lots of times when doing nothing doesn't matter.

so keep track of interval variable (you can use static variable keep scope small possible). this:

private sub _tmrall_tick(sender object, e eventargs) handles _tmrall.tick     static intervalcount integer = 0      intervalcount += 1      if intervalcount mod 25 = 0         phandleclickdelayrepeat()     end if      if intervalcount mod 100 = 0         phandleskype()     end if      if intervalcount mod 43 = 0          phandlemouse()     end if end sub 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -