作業中のアプリケーションがあり、電子メールを送信しようとすると、電子メールは正常に送信されますが、アプリケーションは閉じられるまで 50% の CPU を使用します。
問題を引き起こしている send メソッドは次のとおりです。
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
}
}
}
これを機能させるために何をすべきかわかりません。助けていただければ幸いです。
ありがとう、