Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7677959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:32:15+00:00 2026-05-31T17:32:15+00:00

I have some code that creates a Process instance and later starts it. There’s

  • 0

I have some code that creates a Process instance and later starts it. There’s some logic that need to check if the Process has been started. HasExited can be used to check if a started process has been exited, but I can not find a similar function for HasStarted. At first glance StartTime looked like a good option, but this function will throw if the process has exited. Also, the documentation says that StartTime only has meaning for started processes.

What is the “correct” approach for determining if a process has started (has been started, but might have quit)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:32:16+00:00Added an answer on May 31, 2026 at 5:32 pm

    While the methods suggested by others will work, it is not the most efficient way to handle such things. If you keep a loop checking whether the Process has exited or not, you will waste a lot of system resources.
    Your concern should be to just know when the process is exiting, and not sit looping for it to check whether it has exited. So, the correct way is to handle Events.

    The code below explains how to do that using Events.

    // Declare your process object with WithEvents, so that events can be handled.
    private Process withEventsField_MyProcess;
    Process MyProcess {
        get { return withEventsField_MyProcess; }
        set {
            if (withEventsField_MyProcess != null) {
                withEventsField_MyProcess.Exited -= MyProcess_Exited;
            }
            withEventsField_MyProcess = value;
            if (withEventsField_MyProcess != null) {
                withEventsField_MyProcess.Exited += MyProcess_Exited;
            }
        }
    }
    
    bool MyProcessIsRunning;
    private void Button1_Click(System.Object sender, System.EventArgs e)
    {
        // start the process. this is an example.
        MyProcess = Process.Start("Notepad.exe");
    
        // enable raising events for the process.
        MyProcess.EnableRaisingEvents = true;
    
        // set the flag to know whether my process is running
        MyProcessIsRunning = true;
    }
    
    private void MyProcess_Exited(object sender, System.EventArgs e)
    {
        // the process has just exited. what do you want to do?
        MyProcessIsRunning = false;
        MessageBox.Show("The process has exited!");
    }
    

    EDIT:
    Knowing whether the process has started or not should be easy since are starting the process somewhere in the code. So you can set a flag there and set it to false when the process is exiting. I updated the code above to show how such a flag can be set easily.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that creates a new site in SharePoint. Upon browsing to
I have some code that creates a bunch of UITextViews and puts them into
I have some code that dynamically creates a new button through JavaScript that when
I have some javascript code that creates an img tag with a mouseover callback,
I have some Javascript code that creates 2 arrays: One for Product Category and
I have some code on my PHP powered site that creates a random hash
we have some C++ code that we need to create a make file in.
I have some code which I did not originally create that uses _beginthreadex and
I have some code that gives a user id to a utility that then
I'm writing some code that needs to process an arbitrary number of lists of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.