そのため、私はしばらくの間、をSystem.Net.Mail.MailMessage
介して電子メールを送信するためのオブジェクトを使用しています。を実装SmtpClient
しているところに気づいたので、常にブロック内で使用しています。MailMessage
IDisposable
using
using(MailMessage msg = new MailMessage())
{
msg.To = blah... etc;
...
smtpclient.Send(msg);
}
メタデータから、の実装に関するこの情報を見ることができますMailMessage
// Summary:
// Releases all resources used by the System.Net.Mail.MailMessage.
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public void Dispose();
//
// Summary:
// Releases the unmanaged resources used by the System.Net.Mail.MailMessage
// and optionally releases the managed resources.
//
// Parameters:
// disposing:
// true to release both managed and unmanaged resources; false to release only
// unmanaged resources.
protected virtual void Dispose(bool disposing);
しかし、私は疑問に思っています、なぜMailMessage
実装するのIDisposable
ですか?はすべてを処理するため、ネットワーク関連のアイテムとは何の関係もないようSmtpClient
です。
添付ファイルのファイルハンドルを保持している可能性があるためでしょうか?他に忘れているものはありますか?