Solved

Need to Run the Windows Service on monthly basis

Posted on 2011-09-22
7
342 Views
Last Modified: 2012-08-14
I Can i have a sample code to run the Windows service on monthly basis
0
Comment
Question by:Umashankar_Guna
7 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36579407
You can simply do it using Windows Task scheduler.Follow thw below steps
1. Goto the Scheduled Tasks. Double click on Add Scheduled Task.
2. A wizard will open up. Use it to schedule a job as usual.
3. Once the schedule is added, right click on it and goto properties.
4. In the Task tab, in the Run area provide the below command      net start "<windows service name>"
5. Click on OKIf you want to schedule for stoping a service use      net stop "<windows service name>"
for restarting      
net restart "<windows service name>"

refer

http://www.eggheadcafe.com/community/aspnet/2/10142484/schedule-the-windows-service-to-run-daily-or-weekly-or-monthly-at-specific-time-like-5-am.aspx
0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
ID: 36579964
0
 

Author Comment

by:Umashankar_Guna
ID: 36579997
Hi but my project requirement is that we need to achive this in windows service can you help me on that.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 40
ID: 36580829
Is the computer restarted regularly, or is it a machine that is left on all the time.

If it is restarted regularly, simply set the service for an automatic Start.

In the OnStart event, check for date you have saved somewhere. If the date is one month old or more, run the service and update the saved date.

If the date is less than one month, stop the service.

0
 
LVL 1

Expert Comment

by:MrKevorkian
ID: 36587652
I would do it like this.

1. add a timer to your service class with an interval of a day
2. when the timer elapses,
2.1 turn the timer off
2.2 see if today is equal to 1.
2.3 if not return out of the method
2.3 if it is - do your processing
2.4 when you have finished processing turn the timer back on

     
        private Timer timer;

        public void Start()
        {
            timer = new Timer(86400000);
            timer.Elapsed += TimerElapsed;
            timer.Enabled = true;
        }
        
        private void TimerElapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                timer.Enabled = false;
                var now = DateTime.Now;

                if (now.Day != 1)
                {
                    return;
                }

                //else do you processing

               timer.Enabled = true;

Open in new window

0
 
LVL 1

Expert Comment

by:MrKevorkian
ID: 36587704
btw - Timer is System.Timers.Timer
0
 

Author Closing Comment

by:Umashankar_Guna
ID: 36667791
Thanks for providing the Very good link which provides teh solution. it works perfect.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question