Some of the actions that my website users take are sending emails. The code that sends emails may be blocked for a while, so I want to do this from the HTTP request handler thread.
I am currently using something like:
ThreadPool.QueueUserWorkItem(o => { try { email.Send(); } catch (Exception ex) { _log.Error("Error sending email", ex); } });
For the most part this works. However, the website operates in an environment in which the application pool can be recycled.
From time to time, I do not receive an email to be sent, and I suspect that this work item in the threadpool queue is deleted during the disposal of the application pool.
How can I perform such ansync operation and guarantee that it will be completed in that case?
Drew noakes
source share