Plumbing the Depths of the ThreadAbortException Using Rotor
Subject:   more trouble..
Date:   2007-07-17 06:27:28
From:   Fuel

let's say that the working thread(the one which eventually we want to Abort) waits on a process to exit

void ThreadProc()
Process process;

// main thread

the problem is that the exception is not thrown ! the main thread waits on the thread to join until the thread exists. the Abort() is not delivered but until the thread exists (returns from Process.WaitForExit).

i was looking for an explaination but could not find any since now.

If the Abort() queues an APC to the thread, it seems that this is not processed because the thread is not on an alertable state.
And it stays that way, it's not even put by the scheduler and this is because it seems like its a non-waitable wait function like WaitForSingleObject on the process handle.

but thats not all.
i tried something else. instead of waiting with Process.WaitForExit() on the process, i used pinvoke and called:
Process proc = Process.GetProcessById(3504);
WaitForSingleObjectEx(proc.Handle, -1, 1); // last value tells that the wait is alertable

this does NOT work either !

what is happening with that thread !?