我有一个正在处理的应用程序,当我尝试发送电子邮件时,电子邮件发送成功,但应用程序随后使用 50% 的 CPU 直到它被关闭。
这是导致问题的发送方法。
public void Send()
{
if(System.String.IsNullOrEmpty(this.Server))
{
throw new PreferenceNotSetException("Server not set");
}
if(System.String.IsNullOrEmpty(this.From))
{
throw new PreferenceNotSetException("E-Mail address not set.");
}
if(System.String.IsNullOrEmpty(this.To))
{
throw new PreferenceNotSetException("Recipients E-Mail address not set.");
}
using(System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(this.From, this.To, this.Subject, this.FormattedText))
{
message.IsBodyHtml = true;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(this.Server);
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
int temp = System.Net.ServicePointManager.MaxServicePointIdleTime;
System.Net.ServicePointManager.MaxServicePointIdleTime = 1;
try
{
client.Send(message);
}
catch(System.Exception ex)
{
//For debugging only.
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
finally
{
System.Net.ServicePointManager.MaxServicePointIdleTime = temp;
//client.Dispose(); No dispose in .Net 2.0
}
}
}
我不知道该怎么做才能使这项工作,任何帮助将不胜感激。
谢谢,