Why a thread is aborted in ASP.NET MVC (again)?
        Posted  
        
            by Dario Solera
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Dario Solera
        
        
        
        Published on 2010-04-28T16:04:22Z
        Indexed on 
            2010/04/28
            16:13 UTC
        
        
        Read the original article
        Hit count: 288
        
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?
© Stack Overflow or respective owner