Process.HasExited为true但进程仍然存在

时间:2016-03-06 14:11:10

标签: c# windows process

在等待某个进程退出时,我发现当进程仍然存在于任务管理器中时,Process.HasExited为true,而Process.WaitForExit(0)返回false。知道为什么吗?

这个问题与Process.HasExited returns true even though process is running?不同,因为在那个问题中,WaitForExit返回true。

{编辑2}

它看到退出进程在global-destruct上抛出异常,可能导致调试对话框打开。 (因为原因,在我的环境中无法看到它)所以这个过程是半死的?退出但没有退回?

{编辑}

在进程上调用CloseMainWindow()然后我等待它退出。主窗口确实关闭了。但这个过程仍然没有退出。

从调试器添加对象的转储 请注意,signaled为false,hasExitTime为false,ExitCode返回异常。 Just HasExited是真的。

        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      

0 个答案:

没有答案