c# - Which is the best practice to call a method every x seconds? -


i have program controls , communicate microprocessor. program sends commands microprocessor , receives feedback @ same time command sent showing same in various text boxes.this activated/fired command control. need implement feedback not related command , therefore not activated user, (current , temperature measurement) relevant status of machine controlled micro. not idea time message sent on micro side, rather receive information , process same every x seconds on pc side. in way can include selector different update intervals. controlling motor , heater.

the question is: best practice call relevant classes process such messages( current , temperature), timer, new thread timer, backgroundworker,something else?

interface: recommend create startpoll() , endpoll() inside controller class: place, necessary information avoid multiple-call, interleaving etc. in scope.

implementation: recommend spinning off dedicated thread: thread pool , other built-in mechanisms not designed work, has high degree of independance rest of app (such communicating other hardware). thread started startpoll() , signalled end endpoll().

timer: definitly not recommend using timer - go straight parallel-call-hell, if 1 check takes longer wait next check (or need plumbing code avoid that). recommend calculate ealiest next start time before start work cycle, when finished waitone() on stop signal remaining time.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -