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 6114521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:59:03+00:00 2026-05-23T14:59:03+00:00

My application need to wait until specific process will be started. I am doing

  • 0

My application need to wait until specific process will be started. I am doing it this way

while (Process.GetProcessesByName("someProcess").Length == 0)
{
    Thread.Sleep(100);
}

Is there any other way(more elegant) how to accomplish this, with functionality similar to WaitForExit()? Thanks for answers.

  • 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-23T14:59:04+00:00Added an answer on May 23, 2026 at 2:59 pm

    Take a look at the ManagementEventWatcher class.

    Specifically, the code example at the bottom of the link shows you how to setup a ManagementEventWatcher to be notified when a new process is created.

    Code copied from MSDN code example (could stand a little cleanup):

    using System;
    using System.Management;
    
    // This example shows synchronous consumption of events. 
    // The client is blocked while waiting for events. 
    
    public class EventWatcherPolling 
    {
        public static int Main(string[] args) 
        {
            // Create event query to be notified within 1 second of 
            // a change in a service
            WqlEventQuery query = 
                new WqlEventQuery("__InstanceCreationEvent", 
                new TimeSpan(0,0,1), 
                "TargetInstance isa \"Win32_Process\"");
    
            // Initialize an event watcher and subscribe to events 
            // that match this query
            ManagementEventWatcher watcher =
                new ManagementEventWatcher();
            watcher.Query = query;
            // times out watcher.WaitForNextEvent in 5 seconds
            watcher.Options.Timeout = new TimeSpan(0,0,5);
    
            // Block until the next event occurs 
            // Note: this can be done in a loop if waiting for 
            //        more than one occurrence
            Console.WriteLine(
                "Open an application (notepad.exe) to trigger an event.");
            ManagementBaseObject e = watcher.WaitForNextEvent();
    
            //Display information from the event
            Console.WriteLine(
                "Process {0} has been created, path is: {1}", 
                ((ManagementBaseObject)e
                ["TargetInstance"])["Name"],
                ((ManagementBaseObject)e
                ["TargetInstance"])["ExecutablePath"]);
    
            //Cancel the subscription
            watcher.Stop();
            return 0;
        }
    }
    

    Edit

    Simplifed example with TargetInstance.Name = 'someProcess' filter added.

      var query = new WqlEventQuery(
                    "__InstanceCreationEvent", 
                    new TimeSpan(0, 0, 1), 
                    "TargetInstance isa \"Win32_Process\" and TargetInstance.Name = 'someProcess'"
                  );
    
      using(var watcher = new ManagementEventWatcher(query))
      {
        ManagementBaseObject e = watcher.WaitForNextEvent();
    
        //someProcess created.
    
        watcher.Stop();
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when my application in tombstoning I need to wait until WebClient UploadStringAsync will return
I am writing unit tests for a multi-threading application, where I need to wait
I am working on a j2me application and I need to wait for a
Within my JavaEE web application, I need to process incoming messages strictly in the
I need that android application do something ant specific time of the day, for
The application need write file's last modification date. void Dater(String DateFile) { File file
In the java web application need to select the file from server and print
Almost all the activities in my application need to interact with a web server
Hi every body i am new in iPhone application development. In my application need
In our enterprise application we need to attach files to a document. We have

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.