简体   繁体   中英

SmtpClient.SendAsync decrease or increase performance?

If I have 2 SmtpClient objects and I call SendAsync() method on both simultaneously, will these 2 send requests be processed sequentially in one thread or simultaneously in more than one? What is the implementation of SendAsync() method?

If every SendAsync() method call is processed in new thread from the web server thread pool, this can lead to decreasing free threads in web server thread pool and thus decrease the overall performance (if the thread pool max limit is hit).

I've search MSDN documentation, but I didn't find the explanation how asynchronous methods are handled.

For any one SmtpClient object, you can only send one message at a time... MSDN Documentation says:

"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."

It's highly likely that under the covers the calls remain async, relying on callbacks from a lower layer (ie. Winsock, used in async mode) to drive continued processing. I would expect a thread to be able to process multiple async send calls without having to wait for earlier ones to complete. It would make no sense, for reasons of throughput and resource usage, to process async calls issued from the client in a sync fashion or thread-per-call further down the comms stack.

For just 2 calls it's pretty likely that they will be processed 'pseudo-concurrently' (with a handler for each taking turns to handle async notifications from WinSock) by a single thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM