C# ThreadAbortException, find who is calling the abort

331 Views Asked by At

I have C# method that is implemented as a stored procedure. The stored procedure is run from SQL Server

The method just launches a separate native process and then loops using HasExited & WaitForExit(500) methods until the native process has exited out.

In some cases the native process can take a few hours to exit out and when it does, intermittently the C# method receives a ThreadAbortException. Below is the stack

System.Threading.ThreadAbortException: Thread was being aborted.
   at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
   at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
   at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
   at System.Diagnostics.Process.WaitForExit(Int32 milliseconds)
   at MYSQLCLRLib.MYAPP.MyMethod(String operation, String executable, String bkParam, String stdin)

I have checked my code and there is no call to Thread.Abort(). How do I figure who and why the abort is being sent?

1

There are 1 best solutions below

0
Akshay Phadke On

If you paste some snippet of your try catch block it will be great . but in your case thread.Abort() or Abort should be somewhere in try block.SUppose , if your thread inside the try block you still want to abort that thread , cant write abort everywhere so .

try
{
.. Aborting thread here

}
catch(ThreadAbortException)
{
throw;
}
catch(Exception ex)
{
..Exception code
}