Quick question. Just want to confirm that a network call such as to a SMTP server doesn’t take up any CPU usage. It only blocks one of my request handling threads and the user who triggered the email has to wait while my webserver is done with the SMTP call. If i send the email in another thread and let the user thread go on, then I get rid of this problem. Right???
One colleague of mine suggested using a separate custom web service that would send an email using a smtp server?
I think your best approach is simply to use the SendAsync method of the SmtpClient class to asynchronously send the email.
For example:
You can even pass in a delegate as the second parameter to the SendAsync method which will act as a callback, and be invoked when the SendAsync method completes. Please see the example on the MSDN site here.
This should give you the best of both worlds in that you can send the email asynchronously without tying up your main executing thread, whilst also avoiding the complexities of spawning and managing your own threads (or writing a separate ‘service’).