Wednesday, May 11, 2011

How i can send mail at 12:00 pm of every day in asp.net application ?


You can start a thread which handles sending the emails. The thread can be started when the application starts. Use Application_Start function in Global.asax to do so. Here is what your code will look like .. its not tested but will give you a fair idea of what I am talking about.

 public System.Threading.Thread emailSender = null;
        protected void Application_Start(object sender, EventArgs e)
        {
            emailSender = new System.Threading.Thread(
                new System.Threading.ThreadStart(RunEmailSender));
            emailSender.Start();
        }
        private void RunEmailSender()
        {
            // Always keep running.
            while (true)
            {
                System.Threading.Thread.Sleep(60000);
                try
                {
                    SendEmails();
                }
                catch (Exception ex)
                {
                    // Log any exceptions here
                }
            }
        }
private void SendEmails()
        {

        } 

No comments :

Post a Comment