Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me to solve my problem



I am using the windows application to send mail to no of people fetching the data from my database. Here i used timer control and set the timer interval to 86400000 so it will execute every 24 hr . For time begin i thought i am done with my task but now i want to execute the timer at 4 AM . how can i achieve this with my code , Here is my Code :

C#
private void tmrScheduler_Tick(object sender, System.EventArgs e)
        {
            try
            {
                tmrScheduler.Stop();
                tmrScheduler.Interval=86400000;
                //Only for the ASLC Module
                
                SendNotification();
                
                //to send the mails to the respective User regarding the Policy Expiry
                //For only PolicyException Module
                SendPolicyExpiryNotificationMails();
                GetNullandVoidData();
            }
            catch(Exception Ex)
            {
                throw Ex;
            }
            finally{tmrScheduler.Start();}

        }




I am call this function in page Load


Please Help in Executing this Timer at Specific time EX: at 4 AM or 12 pm etc.



Thanks & Regards

Rajesh Yerramsetti
Posted
Updated 15-Mar-13 2:27am
v2

1 solution

First off, setting a timer to a 24 hour interval is not a brilliant idea - it doesn't give any real flexibility. I would set it to a smaller interval (a minute for example) and use a counter to tell when a period has elapsed instead, or store a time-to-do-it value and check if that is in the past. If so, it's time to do whatever action the timer is there for.

But I wouldn't do a task like that from a Timer - I would use the Windows Task Scheduler[^] to run my app at the specified time instead...
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900