Solved

Need to Run the Windows Service on monthly basis

Posted on 2011-09-22
7
344 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 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MYSQL responding very slow 3 65
SSIS Column mapping 5 40
How does GeoJson relates to Leaflet and Mapbox? 4 47
CSS styling problem 3 23
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

737 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