timer that runs 2 of every 3 seconds c# -
is there way run program every 2 of 3 seconds? know can make timers run every n milliseconds, not every n of m seconds. basic example, pretend want have 2 functions both add integer value. 1 function run 2 of every 3 seconds , add 5 value. second function add 100 same value, run 1 second other 1 doesn't run. make sense?
the simplest way keep internal representation of second on , switch based on different execution.
private int counter = 0; private int whichsecond = 0; void runseverysecond() { if (whichsecond < 2) { counter += 5; whichsecond++; } else { counter += 100; whichsecond = 0; } }
Comments
Post a Comment