Esempio n. 1
0
 public int SendEmail(MailMsg mailMsg)
 {
     this.debugcount    = 0;
     this.lastErrorCode = ErrorCode.ONGOING;
     ThreadCreator.StartThread(new ParameterizedThreadStart(this.sendMail), mailMsg, true);
     while (this.lastErrorCode == ErrorCode.ONGOING)
     {
         try
         {
             Thread.Sleep(300);
         }
         catch (Exception)
         {
             break;
         }
         this.debugcount++;
     }
     return(this.lastErrorCode);
 }
Esempio n. 2
0
        private static void MailThreadScheduler(object obj)
        {
            MailMsg mailMsg = null;

            while (true)
            {
                int num = WaitHandle.WaitAny(LogAPI._waitEmailHandles, 100);
                if (num == 258)
                {
                    lock (LogAPI._lockEmail)
                    {
                        TimeSpan timeSpan = DateTime.Now - LogAPI._lastEmailMerge;
                        if (timeSpan.TotalSeconds < 0.0)
                        {
                            LogAPI._lastEmailMerge = DateTime.Now;
                            timeSpan = DateTime.Now - LogAPI._lastEmailMerge;
                        }
                        if (timeSpan.TotalSeconds <= 5.0)
                        {
                            continue;
                        }
                        if (LogAPI._mergedMail == null)
                        {
                            continue;
                        }
                        mailMsg            = LogAPI._mergedMail;
                        LogAPI._mergedMail = null;
                    }
                }
                if (num == 0)
                {
                    break;
                }
                try
                {
                    if (LogAPI._mailerCounter < 10)
                    {
                        lock (LogAPI._lockEmail)
                        {
                            if (mailMsg == null)
                            {
                                if (LogAPI._emailQueue.Count > 0)
                                {
                                    if (LogAPI._emailQueue.TryDequeue(out mailMsg))
                                    {
                                    }
                                }
                                else
                                {
                                    LogAPI._emailEvent.Reset();
                                }
                            }
                        }
                        if (mailMsg != null)
                        {
                            Interlocked.Increment(ref LogAPI._mailerCounter);
                            mailMsg.Body = new StringBuilder("Dear User, ").AppendLine("<br /><br />").Append(mailMsg._mergedBody).ToString();
                            ThreadCreator.StartThread(new ParameterizedThreadStart(LogAPI.sendMailThread), mailMsg, true);
                            mailMsg = null;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }