Dave Tapson
Dave Tapson

Reputation: 850

C# How to identify member of a set of processes with same name?

I have a parent app that runs multiple instances of a child app. I want to be able to disable a 'Start'button against each of these processes should the process be running.

Getting a list of running instances of the app is easy enough (Process.GetProcessesByName("Bob")) - what I need to be able to do is loop through the list of processes returned (all of the same name) and identify which instances are running.

The instances have a public variable called ClientId - how can I read the ClientId's of the processes to see which one's are running?

Is there a better approach?

Upvotes: 2

Views: 346

Answers (1)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112712

If you are starting the processes with Process.Start(fileName), you can store the process object returned:

Process myProcess = Process.Start(fileName);

Processes have a HasExited property that you can check.

Upvotes: 1

Related Questions