C# how to correctly dispose of an SmtpClient?

后端 未结 6 1113
小鲜肉
小鲜肉 2020-12-05 12:57

VS 2010 code analysis reports the following:

Warning 4 CA2000 : Microsoft.Reliability : In method \'Mailer.SendMessage()\', object \'client\' is not disposed along

6条回答
  •  北海茫月
    2020-12-05 13:56

    using (SmtpClient client = new SmtpClient())
    {
        client.Send(Message);
        DisposeAttachments(); 
    }
    

    Interesting - contrary to .NET 3.5, SmtpClient implements IDisposable in .NET 4.0, learning new things every day.

提交回复
热议问题