c# - What are best practices for using SmtpClient, SendAsync and Dispose under .NET 4.0 -
How do I manage SmtpClient now, it is disposable, but a bit confused, especially if I call using SendAsync I am doing Potentially I should not send a dispatch unless SendAsync is complete. But I should call it anytime (for example, using "experiment") scenario is a WCF service that periodically sends emails when calls are made. Most calculations are faster, but sending e-mail can take a second or even more time, so async is better.
Should I create a new SMTP client every time I send mail? Can I make one for the whole WCF? help!
Update If any difference happens, each email is always customized for the user. The WCF is hosted on Azure and Gmail is used as a mailer. You always It is a bit annoying IDisposable on the possibility as soon as possible in the case of asynchronous calls , This message is on the callback after it has been sent.
var message = new mailmessage ("from", "to", "subject", "body")) Var client = new smtpClient ("host"); Client.SendCompleted + = (s, e) = & gt; {Client.Dispose (); Message.Dispose (); }; Client.SendAsync (message, empty);
SendAsync does not accept callback.
Comments
Post a Comment