Solved

Need to Run the Windows Service on monthly basis

Posted on 2011-09-22
7
339 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now