Jump to content

Elwing

Member
  • Posts

    5
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Elwing reacted to Franck in Executing method on schedule in C#   
    1 - Get the current time
    2 - Get difference between now and next iteration
    3 - Start a System.Timers.Timer with the elapsed time and once it triggers run your code.
     
    then rinse and repeat. Why ? because the calculation for next iteration might change due to daylight saving time and you need to recompute it. You can't simply set 24 hours in milliseconds.
     
    Now why using specially the timer in System.Timers.Timer you would say. The reason is because this specific timer uses the windows scheduler which instead of spin wait it is simply not using any cpu and has a trigger set in the scheduler. Once the scheduler get to the set elapsed value it triggers your event. Not that it is NOT an atomic operation.
    It might run the code at 6:59.999. The scheduler try to execute the trigger as close as possible to the requested time.
×