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

I have this application that need to do some things in protected paths (like
I am writing unit tests for a multi-threading application, where I need to wait
In the java web application need to select the file from server and print
In an application I need to execute other programs with another user's credentials. Currently
I have two application that need to talk to each other. App1 needs to
In my C# application I need to create a .resx file of strings customized
I have an application I need to analyze. I have the source code here.
For my web application I need to close the child window whenever the parent
In my application I need to show in template stocks for my products. So
In my iPhone application I need to use GPS (CoreLocation to be exact) to

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.