我在发送电子邮件时出现进度条错误
问题描述:
我想在发送自动生成的电子邮件时有一个进度条,但出现错误。请帮我解决这个问题。任何类型的反应都非常感谢。我在发送电子邮件时出现进度条错误
我不知道我是否在正确的道路上,我是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'来只捕获你知道如何处理的特定异常 –
看起来你正在启动一个反复启动相同方法的线程再次......看起来像一个无限循环。 –