0

A particular function is called in some intervel of time .but the problem is update function is written in to that function .but before updating the mailsend=1 another call is get.so how to block

In Global.asax page call the function SendMailReminder()

public static System.Timers.Timer _timer = null; void Application_Start(object sender, EventArgs e) { // Code that runs on application startup try {

            if (ObjUsers.GetBoolReminder())
            {
                _timer = new System.Timers.Timer(30000);
                _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
                _timer.Start();
            }



        }
     private void _timer_Elapsed(object sender, ElapsedEventArgs e)
      {

     objCMailSettings.SendMailReminder();
       }

In function SendMailReminder contains

      for (int i = 0; i < dt.Rows.Count; i++)
        {
            DateTime ledate = DateTime.Now;
            DateTime dtnw;
            var Reminder = "";
            int remind = 0 ;

            string strsSql1 = "SELECT  distinct (LE_LEDATA.LE_DATE) as               LE_DATE,LE_LEDATA.LE_LENR,LE_LEDATA_ART.LE_BEZUGNUM as LE_BEZUGNUM from LE_LEDATA inner join LE_LEDATA_ART " +
           " on LE_LEDATA.LE_LENR=LE_LEDATA_ART.LEA_LENR where LE_USERID=" + dt.Rows[i]["USERID"].ToString() + " and LE_IsArchiv=0 and MailSend=0 ORDER BY LE_DATE DESC";

            DataTable dt1 = dab.Fill(strsSql1, CommandType.Text).Tables[0];
     for (int j = 0; j < dt1.Rows.Count; j++)
            {


                long tickDiff = DateTime.Now.Ticks - ledate.Ticks;
                tickDiff = tickDiff / 10000000; //have seconds now
                int NrOfDays = (int)(tickDiff / 86400);



                if ((remind < NrOfDays) && (remind!=0))
                {



                    MailMsg.From = new MailAddress(UserMailId);
                    string MailTo = dt.Rows[i]["EMAIL"].ToString();
                    try
                    {
                        if (MailTo != "")
                        {
                            MailMsg.To.Add(new MailAddress(MailTo));
                            MailMsg.Subject = "Erinnerung nach";
                            MailMsg.IsBodyHtml = true;
                            MailMsg.Subject = sSubject;



                            smtpClient.Send(MailMsg);


                        }

                    }
Vineeth S
  • 291
  • 1
  • 2
  • 9

0 Answers0