System.Diagnostics.Process

This is a discussion on System.Diagnostics.Process within the C# Programming forums, part of the General Programming Boards category; Okay, this is more of a .NET Framework question...actually I'm using VB .NET...but I don't think that part matters. Here's ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446

    System.Diagnostics.Process

    Okay, this is more of a .NET Framework question...actually I'm using VB.NET...but I don't think that part matters. Here's the issue:

    I create a process object
    I start the process object
    I wait for exit
    Everything is Okay until here
    Now I want to get some info from the process, for example the PeakWorkingSet or maybe PeakVirtualMemorySize. I get an exception, the stated reason being that the process has already exited. Is there any way around this?

    I read something on the net that indicated that this is the intended behavior. NOOO!!!!

    This just seems crazy to me, because some of this info isn't even that interesting UNTIL the process has exited, and in other cases (for example I start the process then try to fetch the PID then wait for exit) I will still get the exception because the process runs so quickly that I don't even get a chance to look at the properties of it. And, being a c programmer, I KNOW that this info really does persist at the OS level even after the process exits (until the programmer discards hProcess or hKernelJobObject). What gives?! I really don't want to rewrite all of the Process code using unmanaged calls if I don't have to...
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I've never done so with .NET, but it looks like you are looking for the capability to act as a debugger - this allows you to step through the execution of the program you are interested in and query it for various information.

    There's an API for this, but I dont know how to do so in .NET

  3. #3
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    I don't necessarily want to be able to step through the child process, but I do want to gather statistics on the process as a whole AFTER it has completed. This is basically what the Win32 API's CreateJobObject, QueryInformationJobObject, etc. do--these only require a handle to a kernel job object, and as long as that handle is around, the statistics are available. There are also API's like GetProcessTimes, which require the handle to the process to get things like start and complete times. I also noticed that not all the fields in the System.Diagnostics.Process object are invalid after the process completes. For instance, the ExitCode, ExitTime, Id, and Handle are valid. But most statistics and even StartTime are not available any longer. I read somewhere on the NET last night that the System.Diagnostics.Process object relies on Performance Counters to get some information, so maybe that is why some info is not available (I'm not familiar with that method of gathering process statistics, but maybe it has the limitation that I am seeing).
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21