Search code examples
c#eventstimer

Exactly fire tick event on completion of hour in C# Timer


I want the tick event to fire every hour exactly on completion of the hour. For e.g. it should tick on 8 am then on 9 am then on 10 am etc. It's simple that I need to set the Interval to 3600000.

The problem here is how should I identify when should I start the timer? I'm creating a tool which will run in system tray from the time when user will log on.


Solution

  • Please don't create a program that does nothing but waste memory. That's what Windows' Task Scheduler is for. Run your program every hour from such a task.

    http://msdn.microsoft.com/en-us/library/aa384006%28v=VS.85%29.aspx

    Here's a sample:

    • Go to Start->Programs->Accessories->Scheduled Tasks.
    • On the right side, click "Add Task..".
    • Select your executable.
    • Go to the Trigger tab.
    • Create Trigger with the following selection:

    .

    Run Daily 
    Start today at 8:00 am
    Repeat every 1 Hour
    

    I'm sorry that I can't provide any screenshots since I'm running the german version of Windows 7.