-1
我有一個簡單的基於Windows的應用程序。我用BackgroundWorker
一個接一個發送郵件。 這裏是DoWork
事件處理程序代碼如何從後臺工作的每個狀態的表單
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
MailsSample Mails = e.Argument as MailsSample;
string readings = "To : " + Mails.To_EmailsID + "- ";
char[] delimiterChars = { ',' };
string[] Emails = Mails.To_EmailsID.Split(delimiterChars);
for (int i = 0; i < Emails.Length; i++)
{
try
{
SmtpClient smtp = new SmtpClient(Mails.SMTP, Mails.PORT);
MailMessage msg = new MailMessage(Mails.From_Email, Emails[i], Mails.subject, Mails.body);
string mto = null;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential(Mails.From_Email, Mails.password);
smtp.EnableSsl = true;
msg.IsBodyHtml = true;
msg.Subject = Mails.subject;
//if (textBox1.Text != "")
//{
// Attachment at = new Attachment(textBox1.Text);
// msg.Attachments.Add(at);
//}
msg.Body = Mails.body;
mto = Emails[i];
msg.IsBodyHtml = true;
smtp.Send(msg);
readings += "Sent Successfully.";
}
catch (Exception ex)
{
readings += "Error : " + ex.Message;
}
//Mails.t.AppendText (Environment.NewLine +readings);
}
e.Result = readings;
}
這裏是一個循環,我想取從循環,存儲在「讀數」變量的每一個狀態。我希望從任何文本框中的一個一個的前面單個狀態(讀數)。 有沒有可能在BackgroundWorker
?
的BackgroundWorker.ProgressChanged事件對本作。 – 2014-11-08 19:15:56