Last active
February 6, 2016 22:13
-
-
Save tuan/ac646eb0ef175edfc069 to your computer and use it in GitHub Desktop.
SendMailAsync with cancellation token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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