Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want check if process is run and not working

This is my code and it says running , In the event that process is not running

What I have tried:

Process[] proc = Process.GetProcessesByName("Processname");
                     if (proc.Length > 1)
                     {
                         MessageBox.Show(" Process is Run", "form1", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         Application.Exit();

                     }
                     else
                     {
                         Application.EnableVisualStyles();
                         //   Application.SetCompatibleTextRenderingDefault(true);
                         Application.Run(new Form3());

                     }
Posted
Updated 3-Dec-20 10:00am
Comments
PIEBALDconsult 3-Dec-20 22:41pm    
I think you're looking for how to use a Mutex to detect whether or not the application is already running.
See:
https://www.codeproject.com/Articles/538/Avoiding-Multiple-Instances-of-an-Application

1 solution

You're going to have to come up with more detail that this.

If a process shows up in the list returned by GetProcessesByName, it was definitely launched and is running.

Are you passing in the correct "Processname"? That's going to be the name on the Details tab of Task Manager, like "notepad.exe", or just "notepad".

Are you talking about if you click in the window of an application and it comes back with "Not Responding"?
 
Share this answer
 
v2
Comments
Member 14013003 3-Dec-20 16:39pm    
i using breakpoint and Value proc.Length is 4 , i try proc.Length > 4 and working !
Dave Kreskowiak 4-Dec-20 9:33am    
OK, so your code found 4 instances of whatever process you're looing for. So what if there's just once instance, or none?

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