Skip to content

Instantly share code, notes, and snippets.

@tuan
Last active Feb 6, 2016
Embed
What would you like to do?
SendMailAsync with cancellation token
public class SmtpClientWrapper : IDisposable
{
private SmtpClient _smtpClient;
public SmtpClientWrapper(SmtpClient smtpClient)
{
this._smtpClient = smtpClient;
}
public async Task SendMailAsync(MailMessage message, CancellationToken ct)
{
using (ct.Register(_smtpClient.SendAsyncCancel))
{
await _smtpClient.SendMailAsync(message);
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool p)
{
if (_smtpClient != null)
{
_smtpClient.Dispose();
_smtpClient = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment