Skip to main content
How to create window service using timer?

 Timer timerDailyReport = new Timer();

 protected override void OnStart(string[] args)
        {
            try
            {
             

                StartTimer(timerDailyReport, 60000, timerDailyReport_Elapsed);
             
            }
            catch (Exception ex)
            {
                ErrorLog.WriteonError("OnStart " + ex.Message.ToString());
            }

        }


private void StartTimer(Timer timer, long interval, ElapsedEventHandler events)
        {
            timer.Interval = interval;
            timer.Elapsed += new ElapsedEventHandler(events);
            timer.Enabled = true;

        }


     #region timerDaily_Elapsed
        /// <summary>
        /// this is timer event call according the time frame.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timerDailyReport_Elapsed(object sender, ElapsedEventArgs e)
        {
            your function here
        }

        #endregion

Comments

Popular posts from this blog

How to convert string time to 24 Hours format in SQL. Declare @Test datetime Select  @Test=CONVERT(datetime, '06:59PM' , 120) Select Cast(@Test as time(0))
How to download partial view content using c#? private static string CallApplicationControllerForSnapshotHtml(Guid subscriberId, int duration, long? subscriberUserId, string conString)         {             string myUrl = string.Format(ServiceConfigurationHelper.GetAppSettingValue("GetHtmlContentUrl") + "?subscriberId={0}&duration={1}&SubscriberUserId={2}&conString={3}", subscriberId, duration, subscriberUserId, conString);             WebClient wc = new WebClient();             string requestResult = wc.DownloadString(myUrl);             return requestResult;         }