views:

24

answers:

1

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.

A: 

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.

Steve Townsend