locked
Which timer class is the best to use with TPL tasks? RRS feed

  • Question

  • Hi!

    In my application (in coincidence of some conditions) TPL task (name it task "A") is started for performing some actions. I'm in need  of some  mechanism which can periodically mesure specified time interval (e.g. 10000 milliseconds) and on expiration of this time interval set the bool flag in application to value "true". Task "A" (when it is running) must read the value of the flag and on basis of its value ("true" or "false") execute appropriate actions. So I have a question: which timer is the best to use with TPL? In the past when I wrote a multithreading application with threads I use System.Threading.Timer for this purpose. But now in my new application I use TPL. So shell you answer me - which timer is the best to use with TPL tasks? 

    Monday, July 22, 2013 11:46 AM

Answers

  • Hi ,

    the system.threading.timer can be used , it contains millisecond accuracy .

    else reactive extensions timer can lso be used like

    var timerTask = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1));
    timerTask
    .Subscribe(x =>

      {
     
    //Do Timer work

       });

    Regards,

    Stygen

    • Marked as answer by TownSparrow Monday, July 22, 2013 2:05 PM
    Monday, July 22, 2013 1:22 PM

All replies