Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Determine If a Process Has Exited 

You can use the HasExited property to determine if the process associated to a Process component has stopped running. The property value returns true if the process is closed and false if the process is still running.

NoteNote

This value is only returned for processes that are started by a Process component.

The Process component does not need to close the associated process to obtain the HasExited property. Administrative information such as the HasExited and ExitTime properties are stored regardless of the way the associated process was closed. The information is stored even if the user closes the process by selecting the Close command in its interface. This information is useful if you want to make sure all processes started with your Process components close when you exit an application.

To determine if a process has exited

  • Read the HasExited property of the Process component that was used to open the process.

    The following example shows how to use the HasExited property to determine if the process associated with a Process component called Process1 has been closed. If it is open, call CloseMainWindow to close the application.

    if (!notepad.HasExited)   {    notepad.CloseMainWindow();   }
    

See Also

Community Additions

ADD
Show:
© 2015 Microsoft