0
我想在發送自動生成的電子郵件時有一個進度條,但出現錯誤。請幫我解決這個問題。任何類型的反應都非常感謝。我在發送電子郵件時出現進度條錯誤
我不知道我是否在正確的道路上,我是C#的初學者,只是依靠在線指南。
此行有錯誤
new System.Threading.Thread(new System.Threading.ThreadStart(btnSend_Click));
private void btnSend_Click(object sender, EventArgs e)
{
//Cursor.Current = Cursors.WaitCursor;
try
{
MailMessage loginInfo = new MailMessage();
string em = "[email protected]";
loginInfo.To.Add(em.ToString());
loginInfo.From = new MailAddress("[email protected]");
loginInfo.Subject = "Requesting Supplies";
loginInfo.Body = "We want another supplies for blah blah blah" + System.Environment.NewLine +
"This is a system generated email.";
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "*Pass*");
smtp.Send(loginInfo);
MessageBox.Show("Email has been sent!", "Sent", MessageBoxButtons.OK);
progressBar1.Visible = true;
progressBar1.Style = ProgressBarStyle.Marquee;
System.Threading.Thread thread =
new System.Threading.Thread(new System.Threading.ThreadStart(btnSend_Click));
thread.Start();
}
catch
{
MessageBox.Show("Message not sent please check you internet connection", "Not Sent", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
}
}
什麼是例外? –
你可能想刪除'try/catch',或者至少修改'catch'來只捕獲你知道如何處理的特定異常 –
看起來你正在啓動一個反覆啓動相同方法的線程再次......看起來像一個無限循環。 –