Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Identifying process completion

Identifying process completion

Scheduled Pinned Locked Moved Visual Basic
questionhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sam Marrocco
    wrote on last edited by
    #1

    I've started a process that runs a command line executable and takes several seconds to return. I've attached/enabled events (OutputDataReceived and ErrorDataReceived) to enable the returning of STDOUT and STDERR messages from the process as they appear. All works fine, and all events return the lines of text as they should for stdout and stderr as they appear. But I've noticed that the OutputDataReceived and ErrorDataReceived events continue to be fired and return output *even after* the process.Exited() event has fired. I would have thought that the process had not yet completed until the last of Error and Output events have been caught/raised, but perhaps there is some kind of buffering going on within the Process that I am unaware of. If this is so, how can I know when the Process has *truly* completed-- as in the OUT and ERR data have fired for the last time *and* the process has truly exited? Ideally I would not read the contents of the OUT and ERR until the process is truly completed, therefore telling me that there is no output to follow the Exited() event.

    A 1 Reply Last reply
    0
    • S Sam Marrocco

      I've started a process that runs a command line executable and takes several seconds to return. I've attached/enabled events (OutputDataReceived and ErrorDataReceived) to enable the returning of STDOUT and STDERR messages from the process as they appear. All works fine, and all events return the lines of text as they should for stdout and stderr as they appear. But I've noticed that the OutputDataReceived and ErrorDataReceived events continue to be fired and return output *even after* the process.Exited() event has fired. I would have thought that the process had not yet completed until the last of Error and Output events have been caught/raised, but perhaps there is some kind of buffering going on within the Process that I am unaware of. If this is so, how can I know when the Process has *truly* completed-- as in the OUT and ERR data have fired for the last time *and* the process has truly exited? Ideally I would not read the contents of the OUT and ERR until the process is truly completed, therefore telling me that there is no output to follow the Exited() event.

      A Offline
      A Offline
      Alan N
      wrote on last edited by
      #2

      Your observations of redirected output continuing after the Exited event has fired is accurate. The Microsoft examples are misleading but buried somewhere in the documentation is the information you need, which is that the redirected streams send DataReceivedEventArgs.Data == null when they close. Process.Exited on it's own isn't much use when outputs are redirected and for all practical purposes it's best to wait until all redirected streams have sent null before declaring the process complete. Alan.

      S 1 Reply Last reply
      0
      • A Alan N

        Your observations of redirected output continuing after the Exited event has fired is accurate. The Microsoft examples are misleading but buried somewhere in the documentation is the information you need, which is that the redirected streams send DataReceivedEventArgs.Data == null when they close. Process.Exited on it's own isn't much use when outputs are redirected and for all practical purposes it's best to wait until all redirected streams have sent null before declaring the process complete. Alan.

        S Offline
        S Offline
        Sam Marrocco
        wrote on last edited by
        #3

        Thanks for the response, Alan. A quick check confirms what you stated--that the OutputDataReceived and ErrorDataReceived are raised with a Nothing value for e.data as the last call after returning their respective data. Since this call happens only once (for each Received event) and *only* after the data is completed, I can set a local flag within the process for each Received event when that happens. Between the two flags and the process.hasexited() property I can raise a custom event along the lines of: If Process.HasExited() and OutputDataReceived_IsCompleted and ErrorDataReceived_IsCompleted then Raise Event Process_HasTrulyCompleted() EndIf This seems to be the only guaranteed manner of knowing that all the conditions are met.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups