A
andrew
Hi,
I have the following issue with the Thread.Abort():
The main thread creates a worker thread which waits on a process
termination.
void ThreadProc()
{
Process proc = proc.Start("notepad.exe");
...
proc.WaitForExit();
}
// main thread
Thread th = new Thread(new ThreadStart(ThreadProc));
th.Abort();
The Abort() call from the main thread does not work as expected, to throw
ThreadAbort exception within the thread immediately. Instead it does throw
it after the WaitForExit() call returns.
I tried to search on internet for Thread.Abort() issues and I found a desc
by Chris Sells about the inner workings of Abort() and the fact that it uses
an APC to issue the exception within the thread.
The problem is, if that is true, then I think that WaitForExit() is doing a
non-alertable waiting, its behaviour would explain it.
If thats the case then the MSDN should say that.
But, what i tried was to replace the Process.WaitForExit() call with a
pinvoke call on the WaitForSingleObjectEx with alertable flag set to 1:
void ThreadProc()
{
Process proc;
...
WaitForSingleObjectEx(proc.Handle, -1, 1); // -1 is INFINITE wait value
and 1 is to make the wait alertable
}
this did not work either. the Abort() call does not throw the exception.
can anyone please explain this ?
My second problem relates to the Process.WaitForExit().
I've just had a situation where the process exited but the call does not
return !
The strange thing was that the proc variable had HasExited property
returning true.
So my question is, how reliable is the Process.WaitForExit() ?
I expected that the wait to be close to the complexity and value of the
simple native call of the WaitForSingleObjectEx (or close to).
After all these, I dont feel confident in the way that Process and
Thread.Abort class work.
I have the following issue with the Thread.Abort():
The main thread creates a worker thread which waits on a process
termination.
void ThreadProc()
{
Process proc = proc.Start("notepad.exe");
...
proc.WaitForExit();
}
// main thread
Thread th = new Thread(new ThreadStart(ThreadProc));
th.Abort();
The Abort() call from the main thread does not work as expected, to throw
ThreadAbort exception within the thread immediately. Instead it does throw
it after the WaitForExit() call returns.
I tried to search on internet for Thread.Abort() issues and I found a desc
by Chris Sells about the inner workings of Abort() and the fact that it uses
an APC to issue the exception within the thread.
The problem is, if that is true, then I think that WaitForExit() is doing a
non-alertable waiting, its behaviour would explain it.
If thats the case then the MSDN should say that.
But, what i tried was to replace the Process.WaitForExit() call with a
pinvoke call on the WaitForSingleObjectEx with alertable flag set to 1:
void ThreadProc()
{
Process proc;
...
WaitForSingleObjectEx(proc.Handle, -1, 1); // -1 is INFINITE wait value
and 1 is to make the wait alertable
}
this did not work either. the Abort() call does not throw the exception.
can anyone please explain this ?
My second problem relates to the Process.WaitForExit().
I've just had a situation where the process exited but the call does not
return !
The strange thing was that the proc variable had HasExited property
returning true.
So my question is, how reliable is the Process.WaitForExit() ?
I expected that the wait to be close to the complexity and value of the
simple native call of the WaitForSingleObjectEx (or close to).
After all these, I dont feel confident in the way that Process and
Thread.Abort class work.