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

  • SEARCH
  • Home
  • 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 7997427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:57:47+00:00 2026-06-04T14:57:47+00:00

I have a kept a polling timer to check if a process is running

  • 0

I have a kept a polling timer to check if a process is running or not. I have the following simple code for this:

bool alreadyChecked = false; //check if the wait to check the second time is already over

**Timer_elapsed event**

Process sampleProcess[] = Process.GetProcessesByName("notepad");
if(sampleProcess.length > 0)
{
//Process is running
return;
}
else
{
//Process is not running, so do the following

//Wait for some time and check again (set alreadyChecked = true when the wait is over)
if (alreadyChecked){
//Run the process}
else{
//The process has started running while we were waiting
return;}
    }

I am not able to implement the waiting code inside the event, so that it can wait and then fire the event again. (Even if we implement the wait time, the Timer_elapsed event will be fired by timer again while we were waiting.)

Any suggestions?

  • 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-06-04T14:57:48+00:00Added an answer on June 4, 2026 at 2:57 pm

    You should create a separate thread and use the sleep method, using a BackgroundWorker is the best option. You can also use a timer thread.

    **BackgroundWorker_DoWork event**
    int nTrials = 0; // this method will help you pick any number of trials before launching the applicaion
    bool isRunning = false;
    while((isRunning = Process.GetProcessesByName("notepad") == 0)  || nTrials < 2)
    {
        Thread.Sleep(1000); // w8 1 second before queriying the process name
        nTrials++;
    } 
    
    if ( isRunning ) RunProcess();
    

    Don’t use the sleep method on your main thread or your application will stop handling messages for the sleep time.

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

Sidebar

Related Questions

I have kept hearing this statement. Switch..Case is Evil for code maintenance, but it
this.entityModel.Entities is a source to my datagrid(agdatagrid) . I have kept AutoGenerateColumns=False . i
Based on following table (I have kept spaces between the rows for clarity) Path
I have the following code in my iPhone app CGPoint p = [StaticClass doSomethingWithA:a
I have a python file testHTTPAuth.py which uses module deliciousapi and is kept in
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have you ever obfuscated your code before? Are there ever legitimate reasons to do
Have you ever created or encountered a self modifying code in Java? If yes,
have not tested on windows. but in ubuntu when u disconnect from the network,
I have kept the object into a list. I want to iterate them with

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.