c# - Timer Interval Calling Long Method -
what happen code below if execute()
takes, say, 3000ms finish, being called every 1000ms due timer interval?
timer _timer = new timer(); private void setuptimer() { _timer.tick += new eventhandler(pollingtimeelapsed); _timer.interval = 1000; _timer.enabled = true; _timer.start(); } private void pollingtimeelapsed(object sender, eventargs e) { execute(); }
edit: using system.windows.forms.timer, since system.timers.timer doesn't have .tick
i'm assuming using system.timers.timer class.
since autoreset has default value (which true), elapsed event fired each time 1000ms has elapsed.
if want fire event 1 time, set autoreset false.
if not want fire event while execute-code running, following:
timer _timer = new timer(); private void setuptimer() { _timer.tick += new eventhandler(pollingtimeelapsed); _timer.interval = 1000; _timer.enabled = true; _timer.start(); } private void pollingtimeelapsed(object sender, eventargs e) { try { _timer.stop() execute(); } { _timer.start() } }
Comments
Post a Comment