ReportScheduler.cs This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters //FOR DAILY REPORT void timer_Elapsed ( object sender , ElapsedEventArgs e ) { //Current Time TimeSpan now = DateTime . Now . TimeOfDay ; //Sets Runtime to the time when the report is to be run TimeSpan runTime = TimeSpan . Parse ( ConfigurationManager . AppSettings [ Constants . RunTime ] ) ; //Creating a 2 minute timespan TimeSpan start = now + new TimeSpan ( 0 , 0 , - timerIntervalInSeconds ) ; TimeSpan end = now + new TimeSpan ( 0 , 0 , timerIntervalInSeconds ) ; //If the run time is within the 2 minute timespan, start application if ( runTime >= start && runTime <= end ) Start ( ) ; timer . Enabled = true ; } //FOR WEEKLY REPORT void timer_Elapsed ( object sender , ElapsedEventArgs e ) { timer . Enabled = false ; DayOfWeek dayOfWeek ; //Sets dayOfWeek to the day mentioned in App.Config Enum . TryParse < DayOfWeek > ( ConfigurationManager . AppSettings [ Constants . RunDay ] , out dayOfWeek ) ; if ( dayOfWeek == DateTime . Today . DayOfWeek ) { //Sets Runtime to the time when the report is to be run TimeSpan runTime = TimeSpan . Parse ( ConfigurationManager . AppSettings [ Constants . RunTime ] ) ; //Creating a 2 minute timespan TimeSpan start = now + new TimeSpan ( 0 , 0 , - timerIntervalInSeconds ) ; TimeSpan end = now + new TimeSpan ( 0 , 0 , timerIntervalInSeconds ) ; //If the run time is within the 2 minute timespan, start application if ( runTime >= start && runTime <= end ) Start ( ) ; timer . Enabled = true ; } }