Click here to Skip to main content
14,208,157 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


25 bookmarked
Posted 20 Mar 2012
Licenced CPOL

Scheduling Window Service Daily,Weekly,Monthly

, 20 Mar 2012
Rate this:
Please Sign up or sign in to vote.
Scheduling Window Service Daily Or Weekly Or Monthly


Crate a a Simple window service and scheduling the windows service with some time interval is very easy.but if you get requirement to schedule a windows service daily at 10Am or some specific hours Or every weekly once .Then you will search code in Google but you may not get exact code in Google.Below is article which may help you while scheduling windows service Daily,Weekly or monthly.


As you know to schedule a windows service , we must require timer and Timer has timer interval Property . we have to trigger an event when timer interval Elapsed and timer has ElapsedEventHandler where we can call method to work on.

Using the code

Explain the topic of the article with code and description

Block of code should be set style as "Code" like below.
//Add the windows service dll in to Windows service reference. 

 using SunilWindowsServiceScheduler; 

 //Below  is the code for  OnStart  and  OnStop for windows service 

  protected override void OnStart(string[] args)
        protected override void OnStop()
 // This method you can write in service class of windows service. 

    void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
                #region Process ProcessFeefoResults
                //Call the ProcessFeefoResults                     


            catch (Exception)


// This the static method  can be used for WindowsServiceSchedler 
private static void WindowsServiceSchedler(System.Timers.Timer _timer)
            string _runweekly = Convert.ToString(ConfigurationSettings.AppSettings["Weekly"]);
            string _weeklyeventTriggerTime = Convert.ToString(ConfigurationSettings.AppSettings["WeeklyeventTriggerTime"]);
            string _dayOfWeek = Convert.ToString(ConfigurationSettings.AppSettings["DayOfWeek"]);
            DayOfWeek MyDays = (DayOfWeek)DayOfWeek.Parse(typeof(DayOfWeek), _dayOfWeek);
            string _DailyEventTriggerTime = Convert.ToString(ConfigurationSettings.AppSettings["DailyEventTriggerTime"]);
            Scheduler sch = new Scheduler("SunilWindowsService");
            if (_runweekly == "true")

                sch.ScheduleWeekly(MyDays, _weeklyeventTriggerTime, _timer);
                sch.ScheduleDaily(_DailyEventTriggerTime, _timer);
 // You have to add the details in App.config file to schedule
 //the service daily Or Weekly or Monthly.  
 <!-- Set Event Trigger Timer in 24 hours format  -->
    <!--Configure Window Service Daily  -->
    <!-- Example : for 10:00 PM value="22"  -->
    <add key="DailyEventTriggerTime" value="10" />
    <!--Configure Window Service  Weekly  -->
    <!-- Example : for 10:00 PM value="22"  -->
    <add key="Weekly" value="false" />
    <add key="DayOfWeek" value="Tuesday" />
    <add key="WeeklyeventTriggerTime" value="10" />  


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
India India
Working as Senior Software Engineer in one of the reputed company in Hyderabad, India

Comments and Discussions

QuestionPlease share the complete code with sample service Pin
Member 1028679114-Dec-17 20:41
memberMember 1028679114-Dec-17 20:41 
BugIn case of week not working Pin
Member 996170928-Mar-16 23:50
memberMember 996170928-Mar-16 23:50 
Questionneed help with code Pin
Member 103774944-Sep-15 1:44
memberMember 103774944-Sep-15 1:44 
Questiongood Pin
raghukiranbnv9-Apr-14 21:21
memberraghukiranbnv9-Apr-14 21:21 
GeneralMy vote of 4 Pin
Samit Kr Ghosh30-Mar-14 22:58
memberSamit Kr Ghosh30-Mar-14 22:58 
QuestionNeed Schedule job code Pin
Member 103095221-Oct-13 9:11
professionalMember 103095221-Oct-13 9:11 
QuestionGood article Pin
Tridip Bhattacharjee10-Jun-13 9:05
professionalTridip Bhattacharjee10-Jun-13 9:05 
GeneralMy vote of 5 Pin
VittorPI19-Feb-13 3:46
memberVittorPI19-Feb-13 3:46 
QuestionSMS with windows Service Pin
Dhanashree Dive30-Jan-13 18:32
memberDhanashree Dive30-Jan-13 18:32 
QuestionIs not working with hours and minutes Pin
Member 97336118-Dec-12 23:53
memberMember 97336118-Dec-12 23:53 
AnswerRe: Is not working with hours and minutes Pin
es promotion6-Jan-14 3:10
memberes promotion6-Jan-14 3:10 
GeneralRe: Is not working with hours and minutes Pin
Member 1004855021-Feb-17 19:37
memberMember 1004855021-Feb-17 19:37 
SuggestionYou can set specified time to execute service on daily basis. Pin
Mukund Thakker25-Mar-12 19:27
professionalMukund Thakker25-Mar-12 19:27 
GeneralRe: You can set specified time to execute service on daily basis. Pin
sunileswar26-Mar-12 20:16
membersunileswar26-Mar-12 20:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190612.1 | Last Updated 20 Mar 2012
Article Copyright 2012 by sunileswar
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid