While waiting for a certain process to exit, I observed that while the process still exist in the Task manager, Process.HasExited is true, and Process.WaitForExit(0) return false. Any idea why?
This question is different from Process.HasExited returns true even though process is running? because in that question WaitForExit returned true.
{Edit 2}
It seen that the exiting process is throwing exception on global-destruct, maybe causing the debug-dialog to open. (can't see it in my environment, for reasons) so the process is half-dead? Exited but not returned?
{Edit}
CloseMainWindow() is called on the process and then I wait for it to exit. The main window indeed closes. but the process still doesn't exit.
Adding the dump of the object from the debugger Note that signaled is false, haveExitTime is false, ExitCode returns an exception. Just HasExited is true.
oProcessToBeKilled {System.Diagnostics.Process (Astebreed)} System.Diagnostics.Process
base {System.Diagnostics.Process (Astebreed)} System.ComponentModel.Component {System.Diagnostics.Process}
Associated true bool
BasePriority 8 int
disposed false bool
EnableRaisingEvents false bool
error null System.Diagnostics.AsyncStreamReader
ErrorDataReceived null System.Diagnostics.DataReceivedEventHandler
errorStreamReadMode undefined System.Diagnostics.Process.StreamReadMode
ExitCode 'oProcessToBeKilled.ExitCode' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException}
exitCode 0 int
exited true bool
exitTime {1/1/0001 12:00:00 AM} System.DateTime
ExitTime 'oProcessToBeKilled.ExitTime' threw an exception of type 'System.InvalidOperationException' System.DateTime {System.InvalidOperationException}
Handle 'oProcessToBeKilled.Handle' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException}
HandleCount 1046 int
HasExited true bool
haveExitTime false bool
haveMainWindow true bool
havePriorityBoostEnabled false bool
havePriorityClass false bool
haveProcessHandle false bool
haveProcessId true bool
haveProcessorAffinity false bool
haveResponding false bool
haveWorkingSetLimits false bool
Id 4364 int
isRemoteMachine false bool
m_processAccess 2035711 int
m_processHandle null Microsoft.Win32.SafeHandles.SafeProcessHandle
machineName "." string
MachineName "." string
MainModule {System.Diagnostics.ProcessModule (Astebreed.exe)} System.Diagnostics.ProcessModule
MainWindowHandle 6687910 System.IntPtr
mainWindowHandle 6687910 System.IntPtr
MainWindowTitle "" string
mainWindowTitle "" string
maxWorkingSet 0 System.IntPtr
MaxWorkingSet 'oProcessToBeKilled.MaxWorkingSet' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException}
MinWorkingSet 'oProcessToBeKilled.MinWorkingSet' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException}
minWorkingSet 0 System.IntPtr
Modules {System.Diagnostics.ProcessModuleCollection} System.Diagnostics.ProcessModuleCollection
modules {System.Diagnostics.ProcessModuleCollection} System.Diagnostics.ProcessModuleCollection
NonpagedSystemMemorySize 51344 int
NonpagedSystemMemorySize64 51344 long
onExited null System.EventHandler
OperatingSystem {Microsoft Windows NT 6.2.9200.0} System.OperatingSystem
operatingSystem {Microsoft Windows NT 6.2.9200.0} System.OperatingSystem
output null System.Diagnostics.AsyncStreamReader
OutputDataReceived null System.Diagnostics.DataReceivedEventHandler
outputStreamReadMode undefined System.Diagnostics.Process.StreamReadMode
PagedMemorySize 333660160 int
PagedMemorySize64 333660160 long
PagedSystemMemorySize 387824 int
PagedSystemMemorySize64 387824 long
PeakPagedMemorySize 381906944 int
PeakPagedMemorySize64 381906944 long
PeakVirtualMemorySize 586805248 int
PeakVirtualMemorySize64 586805248 long
PeakWorkingSet 345051136 int
PeakWorkingSet64 345051136 long
pendingErrorRead false bool
pendingOutputRead false bool
PriorityBoostEnabled 'oProcessToBeKilled.PriorityBoostEnabled' threw an exception of type 'System.InvalidOperationException' bool {System.InvalidOperationException}
priorityBoostEnabled false bool
priorityClass 0 System.Diagnostics.ProcessPriorityClass
PriorityClass 'oProcessToBeKilled.PriorityClass' threw an exception of type 'System.InvalidOperationException' System.Diagnostics.ProcessPriorityClass {System.InvalidOperationException}
PrivateMemorySize 333660160 int
PrivateMemorySize64 333660160 long
PrivilegedProcessorTime {00:00:00.5937500} System.TimeSpan
processId 4364 int
processInfo {System.Diagnostics.ProcessInfo} System.Diagnostics.ProcessInfo
ProcessName "Astebreed" string
processorAffinity 0 System.IntPtr
ProcessorAffinity 'oProcessToBeKilled.ProcessorAffinity' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException}
raisedOnExited true bool
registeredWaitHandle null System.Threading.RegisteredWaitHandle
responding false bool
Responding false bool
SessionId 1 int
signaled false bool
standardError null System.IO.StreamReader
StandardError 'oProcessToBeKilled.StandardError' threw an exception of type 'System.InvalidOperationException' System.IO.StreamReader {System.InvalidOperationException}
StandardInput 'oProcessToBeKilled.StandardInput' threw an exception of type 'System.InvalidOperationException' System.IO.StreamWriter {System.InvalidOperationException}
standardInput null System.IO.StreamWriter
StandardOutput 'oProcessToBeKilled.StandardOutput' threw an exception of type 'System.InvalidOperationException' System.IO.StreamReader {System.InvalidOperationException}
standardOutput null System.IO.StreamReader
startInfo null System.Diagnostics.ProcessStartInfo
StartInfo {System.Diagnostics.ProcessStartInfo} System.Diagnostics.ProcessStartInfo
StartTime {3/6/2016 4:37:02 PM} System.DateTime
synchronizingObject null System.ComponentModel.ISynchronizeInvoke
SynchronizingObject null System.ComponentModel.ISynchronizeInvoke
threads null System.Diagnostics.ProcessThreadCollection
Threads {System.Diagnostics.ProcessThreadCollection} System.Diagnostics.ProcessThreadCollection
TotalProcessorTime {00:00:07.2031250} System.TimeSpan
UserProcessorTime {00:00:06.6093750} System.TimeSpan
VirtualMemorySize 542359552 int
VirtualMemorySize64 542359552 long
waitHandle null System.Threading.WaitHandle
watchForExit false bool
watchingForExit false bool
WorkingSet 300617728 int
WorkingSet64 300617728 long
Static members