private void btnFetchEmails_Click(object sender, EventArgs e) { if (ValidateUI()) { btnFetchEmails.Enabled = false; IMailClient client = null; if (rdbImap.Checked) { client = new ImapClient(tbHostName.Text.Trim(), Convert.ToInt32(tbPortNo.Text.Trim()), cbIsSecure.Checked); } else { client = new PopClient(tbHostName.Text.Trim(), Convert.ToInt32(tbPortNo.Text.Trim()), cbIsSecure.Checked); } EmailAutomation emailAutomation = new EmailAutomation(client, tbUserName.Text.Trim(), tbPassword.Text.Trim()); emailAutomation.ProgressValueChanged += new ProgressValueChangedEventHandler(emailAutomation_ProgressValueChanged); emailAutomation.StatusChanged += new StatusChangedEventHandler(emailAutomation_StatusChanged); System.Threading.ThreadStart start = new System.Threading.ThreadStart(emailAutomation.PlayEmailAutomation); System.Threading.Thread t = new System.Threading.Thread(start); t.Start(); while (t.IsAlive) { Application.DoEvents(); System.Threading.Thread.Sleep(200); } emailAutomation.ProgressValueChanged -= new ProgressValueChangedEventHandler(emailAutomation_ProgressValueChanged); emailAutomation.StatusChanged -= new StatusChangedEventHandler(emailAutomation_StatusChanged); btnFetchEmails.Enabled = true; } }
public void PlayEmailAutomation(object objModel) { EmailAutomationModel model = objModel as EmailAutomationModel; var ea = new EmailAutomation(); IMailClient client; ea.ActionChangedEvent += (s, e) => { if (Actionchanged != null) Actionchanged(s, e); }; ea.ProgressValueChangedEvent += (s, e) => { if (ProgressValueChanged != null) ProgressValueChanged(s, e); }; if (model.IsProtocolImap) { client = new ImapClient(model.Hostname, model.Port, model.IsSecure); } else { client = new Pop3Client(model.Hostname, model.Port, model.IsSecure); } ea.MailStatus = model.MailStatus; ea.MailCount = model.MailsToDisplay; ea.PlayEmailAutomation(client, model.Username, model.Password, model.IsProtocolImap, model.MailBox); ea.ProgressValueChangedEvent -= (s, e) => { if (ProgressValueChanged != null) ProgressValueChanged(s, e); }; ea.ActionChangedEvent -= (s, e) => { if (Actionchanged != null) Actionchanged(s, e); }; ea = null; }
public void PlayEmailAutomation(object objModel) { EmailAutomationModel model = objModel as EmailAutomationModel; var ea = new EmailAutomation(); IMailClient client; ea.ActionChangedEvent += (s, e) => { Actionchanged?.Invoke(s, e); }; ea.ProgressValueChangedEvent += (s, e) => { ProgressValueChanged?.Invoke(s, e); }; if (model.IsProtocolImap) { client = new ImapClient(model.Hostname, model.Port, model.IsSecure); } else { client = new Pop3Client(model.Hostname, model.Port, model.IsSecure); } ea.MailCount = model.MailsToDisplay; ea.PlayEmailAutomation(client, model.Username, model.Password, model.MailSearchCriteria, model.MailBox); ea.ProgressValueChangedEvent -= (s, e) => { ProgressValueChanged?.Invoke(s, e); }; ea.ActionChangedEvent -= (s, e) => { Actionchanged?.Invoke(s, e); }; ea = null; }
private void btnFetchEmails_Click(object sender, EventArgs e) { if (ValidateUI()) { btnFetchEmails.Enabled = false; IMailClient client = null; if (rdbImap.Checked) client = new ImapClient(tbHostName.Text.Trim(), Convert.ToInt32(tbPortNo.Text.Trim()), cbIsSecure.Checked); else client = new PopClient(tbHostName.Text.Trim(), Convert.ToInt32(tbPortNo.Text.Trim()), cbIsSecure.Checked); EmailAutomation emailAutomation = new EmailAutomation(client, tbUserName.Text.Trim(), tbPassword.Text.Trim()); emailAutomation.ProgressValueChanged += new ProgressValueChangedEventHandler(emailAutomation_ProgressValueChanged); emailAutomation.StatusChanged += new StatusChangedEventHandler(emailAutomation_StatusChanged); System.Threading.ThreadStart start = new System.Threading.ThreadStart(emailAutomation.PlayEmailAutomation); System.Threading.Thread t = new System.Threading.Thread(start); t.Start(); while (t.IsAlive) { Application.DoEvents(); System.Threading.Thread.Sleep(200); } emailAutomation.ProgressValueChanged -= new ProgressValueChangedEventHandler(emailAutomation_ProgressValueChanged); emailAutomation.StatusChanged -= new StatusChangedEventHandler(emailAutomation_StatusChanged); btnFetchEmails.Enabled = true; } }