Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need to Run the Windows Service on monthly basis

Posted on 2011-09-22
7
Medium Priority
?
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Screencast - Getting to Know the Pipeline

610 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