There's an ASP.NET MVC3 application where some of controller actions use an external mechanism for processing the input data. The input data is first saved into a temporary file and then an external program is being run and the path to the temporary file is passed at the command line. This is done using System.Diagnostics.Process
class.
The external program usually exits promptly - earlier than in one second after it was started, so no problem, just wait for its completion with Process.WaitForProcessExit()
and the dispose the Process
object.
It gets harder if the external program hangs and doesn't exit in a timely manner. It happens very very rarely, but when it happens then Process.WaitForProcessExit()
hangs too and the controller action runs for some time but then the client timeout happens and the controller action is cancelled but there's no way I could find that would cause forcible termination of the external program. I could of cause use Process.Kill()
but I have to wire this call into somewhere such that it's invoked when the controller action is cancelled because of client timeout.
I tried to override Controller.OnException()
but it looks like it's not invoked in this scenario.
How can ASP.NET MVC3 code be changed such that it calls some custom code (such as external program termination) when a client timeout occurs?