Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Process.HasExited为true,但进程仍处于活动状态_C#_Windows_Process - Fatal编程技术网

C# Process.HasExited为true,但进程仍处于活动状态

C# Process.HasExited为true,但进程仍处于活动状态,c#,windows,process,C#,Windows,Process,在等待某个进程退出时,我观察到,虽然该进程仍存在于任务管理器中,但process.HasExited为true,process.WaitForExit(0)返回false。知道为什么吗 这个问题与其他问题不同,因为在这个问题上,WaitForExit返回了true {编辑2} 可以看出,退出进程正在全局析构函数上引发异常,可能导致调试对话框打开。(由于种种原因,在我的环境中看不到它)所以这个过程是半死不活的?退出但未返回 {编辑} 在进程上调用CloseMainWindow(),然后我等待它退出

在等待某个进程退出时,我观察到,虽然该进程仍存在于任务管理器中,但process.HasExited为true,process.WaitForExit(0)返回false。知道为什么吗

这个问题与其他问题不同,因为在这个问题上,WaitForExit返回了true

{编辑2}

可以看出,退出进程正在全局析构函数上引发异常,可能导致调试对话框打开。(由于种种原因,在我的环境中看不到它)所以这个过程是半死不活的?退出但未返回

{编辑}

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

从调试器添加对象的转储 请注意,signaled为false,haveExitTime为false,ExitCode返回异常。刚刚退出是真的

        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      

有何不同?这里没有任何东西表明这一点,或者我们可以使用它。你确定这不是同一个EXE的不同实例吗?SLak-是的,只有一个正在运行的实例,并且进程id匹配。该进程可能产生了另一个进程并继续运行,然后返回。但是WaitForExit也将是真的,不是吗?