我有一個正在處理的應用程序,當我嘗試發送電子郵件時,電子郵件發送成功,但應用程序使用50%的CPU,直到它關閉了。發送電子郵件後,應用程序使用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
}
}
}
我不確定該做什麼,做任何幫助,將不勝感激。
感謝,
如果你打破執行,程序在做什麼? – 2010-11-09 19:26:53
@Albin Sunnanbo:不知道我沒有使用IDE,所以沒有調試。 – Tester101 2010-11-09 19:31:58
@ Tester101,爲什麼不呢?如果你不知道你的程序在做什麼,那麼這是第一個可用的工具。 – 2010-11-09 19:37:07