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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -