Exemple #1
0
 public bool QueueSend(MailUnit unit)
 {
     lock (_lockObject)
     {
         if (_mailQueue.Count >= MaxMailQueueLength)
         {
             return(false);
         }
         else
         {
             _mailQueue.Enqueue(unit);
             return(true);
         }
     }
 }
Exemple #2
0
        private void Process()
        {
            while (_working)
            {
                try
                {
                    lock (_lockObject)
                    {
                        if (_mailQueue.Count > 0)
                        {
                            MailUnit mailUnit = _mailQueue.Peek();
                            switch (mailUnit.SendState)
                            {
                            case MailUnit.State.Init:
                                mailUnit.AsyncSendMail();
                                break;

                            case MailUnit.State.Doing:
                                mailUnit.AsyncSendMailCheck();
                                break;

                            case MailUnit.State.Done:
                                _mailQueue.Dequeue();
                                mailUnit.Dispose();     //释放非托管资源,否则会导致附件文件被占用
                                break;

                            default:
                                _mailQueue.Dequeue();
                                IO.Logger.Write("MailUnit State Error : State - " + mailUnit.SendState.ToString());
                                break;
                            }
                        }
                        else
                        {
                            _working = false;
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    IO.Logger.Write(ex.ToString());
                }

                System.Threading.Thread.Sleep(1000); //5秒
            }
        }