Here is what I do in a controller action:
- create and start a new Thread that does a relatively long processing task (~30 seconds on average, but might be several minutes)
- immediately return the page response so the user knows processing has started (trivially, a Json with a task ID for polling purposes).
At some random point, ThreadAbortException is thrown, so the async task does not complete. The exception is not thrown every time, it just happens randomly roughly 25% of the times.
Points to note:
- I'm not calling Response.End or Response.Redirect - there isn't even a request running when the exception is thrown
- I tried using ThreadPool and I got the same behavior
- I know running threads in ASP.NET has several caveats but I don't care right now
Any suggestion?