Follow me on Twitter at
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:
Watching other processes - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.


Visual Studio Magazine Column Personal Blog


Book Authors




Georgia Tech Bloggers



Watching other processes

Over a year ago, I wrote a Windows Service in .NET to watch the web server process of IIS (InetInfo.exe) and to stop that service and restart it under certain conditions.  I had set the app up to run under a timer and wake up every couple of minutes to check the state of IIS.  While it worked, I always wondered about how do I check for processes that are currently running and a few other things.

Now, thanks to Roy Osherove, I have almost all of what I want.  He gave me the little kick in the "code" pants to head me into a better direction.  I took his code and modified it to what is at the end of this post.  My next step is going to be how to find out when a new process starts...............

static void Main(string[] args)

Process [] localByName = Process.GetProcessesByName("notepad");
for(int i=0;i<localByName.Length;i++)

localByName[i].Exited += new EventHandler(OnExit);
localByName[i].EnableRaisingEvents =



private static void OnExit(object sender,EventArgs e)

Console.WriteLine("The process was finished!");



Roy Osherove said:

Great to know I've helped someone out! :)
# June 19, 2003 4:21 PM

Roy Osherove said:

btw, if you want to knwo when a new process starts, why not periodically check the current process list for any additions and update event handlers as needed?
# June 19, 2003 8:07 PM