If I have 2 SmtpClient objects and I call SendAsync() method on both simultaneously, will these 2 send requests be pro开发者_JAVA百科cessed 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.
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.
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."
精彩评论