private void buttonSend_Click(object sender, EventArgs e) { if (m_timer.Enabled)//表示timer正在工作 { m_timer.Stop(); m_timer.Enabled = false; OnDone(); return; } else if (backgroundWorkerMailSender.IsBusy) { backgroundWorkerMailSender.CancelAsync(); OnDone(); return; } if (comboBoxAccounts.Items.Count < 1) { QMessageBox.ShowWarning("account can not be empty!"); return; } else if (comboBoxAccounts.SelectedIndex < 0) { QMessageBox.ShowWarning("you must select an account!"); return; } else if (String.IsNullOrEmpty(textBoxSubject.Text)) { QMessageBox.ShowWarning("email subject can not be empty!"); return; } else if (String.IsNullOrEmpty(richTextBoxBody.Text)) { QMessageBox.ShowWarning("email body can not be empty!"); return; } else if (listBoxAddresses.Items.Count <= 0) { QMessageBox.ShowWarning("recipients can not be empty!"); return; } else { if (checkBoxTimedSend.Checked) { if (dateTimePickerTimedSend.Value <= DateTime.Now) { QMessageBox.ShowError("the time is in the past!"); return; } m_timer.Interval = dateTimePickerTimedSend.Value.Subtract(DateTime.Now).TotalSeconds * 1000; } else { m_timer.Interval = 1; } } WrappedItem item = (WrappedItem)comboBoxAccounts.SelectedItem; EmailAccount a = item.Account; a.Init(textBoxSubject.Text, richTextBoxBody.Text); object[] addresses = new object[listBoxAddresses.Items.Count]; listBoxAddresses.Items.CopyTo(addresses, 0); job = new MailJob(a, addresses); m_timer.Start(); buttonSend.Text = "Cancel"; buttonQuit.Enabled = false; this.Text = String.Format("{0} - waiting to send...", m_formText); }