Solved

Need to Run the Windows Service on monthly basis

Posted on 2011-09-22
7
341 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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.   …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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