I just want to check if any desired application is already running or not
for eg suppose I have VLC or iTunes or any windows application then how can i figure it out by c# code if it is running or not.
This should be pretty easy to find with a quick Google search, but here you go:
if (Process.GetProcessesByName("process_name").Length > 0)
{
// Is running
}
Replace process_name
with the name of the process you are looking for (i.e. vlc
).
Checking for Self-Process
As pointed out in the comments by @filimonic, if you want to check whether more than one instance of the application is running you can use > 1
in place of > 0
:
if (Process.GetProcessesByName("process_name").Length > 1)
{
// Is running
}
This works by checking that a maximum of 1 processes is currently running.
you can use either Process.GetProcessesByName
if you know the process name or Process.GetProcessesByID
if you know it's ID.