Net.Mail.SmtpClient - SendAsync

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
I was looking at the nature of my application and realizing that I have a "series" of emails to transmit when it runs, I thought that it may be preferable to use Asynchronous sending of the emails that I could continue processing items, when I ran into this error:
"There is already another Asynchronous operation pending"

So...how Async is SendAsync?

I was planning to just execute SendAsync(msg) on all my mail messages and wait for the SendComplete() event on the Asynchronous sending, but it appears I can't "queue" up emails to send, or can I and I'm just doing it wrong?

I would like to not have to wait for each one as I process them, but naturally i will if i must.

Thanks
 
So...how Async is SendAsync?
It's 100% async, but you have misunderstood the purpose of this method being an async call. It is a non-blocking call that lets you resume the code execution immediately, and there is a SendAsyncCancel Method that allows to cancel the transmission in progress. The SendCompleted event exists to receive the transmission results asynchronous. In some cases async sockets is done through device drivers and not .Net threads, so this can make such asynchronous operations faster and freeing .Net resources.
help said:
After calling SendAsync, you must wait for the e-mail transmission to complete before attempting to send another e-mail message using Send or SendAsync.
So to send multiple mails at the same time you need multiple SmtpClient instances.
 
Back
Top