You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now there's a SendAsyncCancel method which is used to cancel the event-based pre-TPL SendAsync. SendMailAsync is implemented as a wrapper around SendAsync (code) but for some reason neglects to take and apply the customary cancellation token.
This means people who want cancellation currently need to add a using statement:
The difficulty is that there's no guarantee that SendMailAsync will continue to be implemented in terms of SendAsync under the covers and that SendAsyncCancel will have any effect. Rather than an extension method, it's more future-proof to bring the responsibility of this coupling much closer to where it belongs: as a detail inside the implementation of SmtpClient.
Proposal
I propose adding these two overloads, copies of the existing overloads but appending a CancellationToken parameter:
class System.Net.Mail.SmtpClient
{
public Task SendMailAsync(string from, string recipients, string subject, string body)
+ public Task SendMailAsync(string from, string recipients, string subject, string body, CancellationToken cancellationToken)
public Task SendMailAsync(MailMessage message)
+ public Task SendMailAsync(MailMessage message, CancellationToken cancellationToken)
}
Implementation would likely be straightforward, with the non-cancellable overloads delegating to the cancellable ones and the SendCompletedEventHandler disposing the cancellation registration.
The text was updated successfully, but these errors were encountered:
If there is enough need to have the overloads and the implementation is straightforward, I think we would be ok with taking a contribution. API approval should be formality in such case.
Problem
Right now there's a
SendAsyncCancel
method which is used to cancel the event-based pre-TPLSendAsync
.SendMailAsync
is implemented as a wrapper aroundSendAsync
(code) but for some reason neglects to take and apply the customary cancellation token.This means people who want cancellation currently need to add a using statement:
Extension method for convenience, in case you want to operate on the original Task without wrapping in an async state machine:
The difficulty is that there's no guarantee that
SendMailAsync
will continue to be implemented in terms ofSendAsync
under the covers and thatSendAsyncCancel
will have any effect. Rather than an extension method, it's more future-proof to bring the responsibility of this coupling much closer to where it belongs: as a detail inside the implementation ofSmtpClient
.Proposal
I propose adding these two overloads, copies of the existing overloads but appending a
CancellationToken
parameter:Implementation would likely be straightforward, with the non-cancellable overloads delegating to the cancellable ones and the
SendCompletedEventHandler
disposing the cancellation registration.The text was updated successfully, but these errors were encountered: