c# - how to use timer in foreach loop -
in company i'm working want build automation tool should run script written in text. i'm new timers, , want make foreach
(not must) run line after line in script , call parser later use. want this:
atimer = new system.timers.timer(10000); // hook elapsed event timer. // set interval 2 seconds (2000 milliseconds). atimer.interval = 2000; atimer.enabled = true; foreach (scriptcell cell in scriptlist) { //fire method when time atimer.elapsed += new elapsedeventhandler(doscriptcommand(cell.celltext)); }
i know wrote doesnt make allot of sense , i'm bit clueless here
ps. looking in other topics before posting q , didnt find nothing seems fill gap
the introduction of await
makes acting on each item in sequence, while waiting period of time between each item, easy:
foreach(var cell in scriptlist) { doscriptcommand(cell.celltext) await task.delay(timespan.fromseconds(2)); }
Comments
Post a Comment