Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
All examples show to get process name.But I want to check if an application (taskmanager->application tab) is running or not by c#.

diagnostics.process returns process names,not application name.
Posted
Comments
Sinisa Hajnal 13-Oct-14 9:44am    
But if you know the application you're looking for, find its process name from task manager and use in your code.
Sergey Alexandrovich Kryukov 13-Oct-14 10:38am    
What's the purpose of that?
—SA
souvikcode 14-Oct-14 4:22am    
Actually I have to show message when an application B starts and when the application ends.This application is called from an application A which is called by my main app.So I can track A easily but not the B.So I'm using timer to check taskmanager if the application exit.

But in taskmanager application tab,I'm getting the application name of B but in process tab it shows another name.B is actually msi installer.So it shows msiexec. I don't know is it unique or not. If there is another msi installer running in this machine,will it show msiexec?In that case there is a possibility of clashing.
Sinisa Hajnal 14-Oct-14 5:15am    
Wouldn't the same problem be with application name? Wouldn't you see two MSI Installer messages?

Why don't you use Process.Exited event? - you start the process B in app A, subscribe to Exited event of B and wait.
souvikcode 14-Oct-14 5:52am    
B is started by A and A is not my app.So how can I associate exited event in B?
With application name there will not be problem because application name is that which I give to application but all msi installer process name is msiexec.

You can try GetProcessesByName[^] - if I read this correctly, simply pass it your application name...but you'll need to test this.


Try this:
C#
// Start the process.
Process proc = Process.Start("your_installer_b.msi"); 

// Wait for the process to end - NOTE THAT THIS WILL BLOCK CALLING APPLICATION
proc.WaitForExit();

MessageBox.Show("Installation B finished.");



Event based wait[^]:

C#
Process proc = Process.Start("your_installer_b.msi"); 
proc.EnableRaisingEvents = True
proc.ProcessExited += your_handler;







If this helps, please take time to accept the solution. Thank you.
 
Share this answer
 
v3
Comments
souvikcode 14-Oct-14 4:16am    
this method returning process name not application name.In task manager you can see a tab named "application"
Sinisa Hajnal 14-Oct-14 5:16am    
Solution updated
souvikcode 14-Oct-14 5:54am    
Actually I am calling application B from application A and application A is called by my main app.So I can associate exited event with A not with B.Mind it A is not developed by me so I can not associate exited event on B by A.
Sinisa Hajnal 14-Oct-14 6:21am    
This is important information that should be up there in the question. All the comments and solutions here assumed you have full control of the code.

Please use improve question and change the description. Still, solutions are valid - you can get process by process name, you can query processinfo to see if you can find the one running app B. Your main application can register ProcessExited on B if you can find it.
souvikcode 14-Oct-14 6:48am    
It is solved.I am calling required process by mainwindowtitle property,it shows application name which I wanted.Then I use wait for exit method and then execute some code.
But exited event is not firing even enableraisingevent is true.Do you know any reason?
SQL
It is solved.I am calling required process by mainwindowtitle property,it shows application name which I wanted.Then I use wait for exit method and then execute some code.
But exited event is not firing even enableraisingevent is true.Do you know any reason?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900