johnnie
johnnie

Reputation: 2057

Windows Service - C#

How can I run a Windows-Service hourly?

Upvotes: 1

Views: 1350

Answers (3)

Sasuke Uchiha
Sasuke Uchiha

Reputation: 91

well you can create a service which works at a time interval of 60 minutes

        timer1 = new Timer();
        this.timer1.Interval = 1000 * 60* 60;
        this.timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
        timer1.Enabled = true;

write this code in the onstart method of the windows service and you will be able to run the service in hourly manner.

Upvotes: 0

Andres
Andres

Reputation: 3414

Based on the description of your problem (which only superficial) I can't think in anything else other than the use of the normal service template provided by VS to create a service and use a Timer to trigger the method that you are interested in running every hour.

About Timer you can also check it out here

For some more info about how to create the service, in can have a look in the msnd web site

As a simple rule of thumb, never forget to disable the timer just before you starting processing your staff and enable it again at the end

Upvotes: 2

Random Dev
Random Dev

Reputation: 52290

Or just write a simple app and use the systems Task Scheduler Service to run your app every hour - no need to write a service at all this way.

Upvotes: 7

Related Questions