ASP.NET MVC & Threads

I have a method that handles sending of emails.  I wrote it so that it would run asynchronously, so that it won’t slow down the web app.  It looks like this:

I added the Thread.Sleep(15000) to see if it works.  To my surprise, it didn’t.  For some reason, the web request doesn’t return until the email thread is done executing.  When I step through the code, it runs through the code right away without waiting and calls the return method on the controller as expected.  But the response is actually never sent to the server until the thread completes – which defies the whole point of it being asynchronous.

What am I doing wrong?  Is this a bug in the MVC framework?  Or did I just overlook something?


I am not sure what’s wrong with the code above but I re-wrote it as show below and it works very well.