Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to manage Timer with Interval

I need to send a report to every month first day at 6am. Please help for the logic for this for time interval for window service, please suggest

private System.Timers.Timer svcTimerForSendEmailSrvc = null;

protected override void OnStart(string[] args)
    {
            svcTimerForSendEmailSrvc = new System.Timers.Timer();
            svcTimerForSendEmailSrvc.Enabled = true;
            svcTimerForSendEmailSrvc.Interval = //here not getting time every month 1st date 6am mail should send
            svcTimerForSendEmailSrvc.Elapsed += new System.Timers.ElapsedEventHandler(svcTimerForSendEmailSrvc_Elapsed);
            svcTimerForSendEmailSrvc.Start();
    }

void svcTimerForSendEmailSrvc_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        SendReportEverymonth1day();
    }

Example i need send email to every month 1 6am.

like 1 jan 2022 next mail 1 feb 2022 next....1 dec 2022

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Third-party solutions such as FluentScheduler or Quartz.NET can be used to schedule code to run on a specific interval, e.g.:

Schedule<MyComplexJob>().ToRunNow().AndEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(3, 0);

A timer cannot.

Another option, as suggested by @Fildor, is to use the Task Scheduler in Windows to start a program that runs your code on a given schedule like for example once a month.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading