C# 如何检查应用程序是否正在运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18015193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:03:03  来源:igfitidea点击:

How to check if application is running

c#process

提问by Pankaj

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.

例如,假设我有 VLC 或 iTunes 或任何 Windows 应用程序,那么我如何通过 c# 代码弄清楚它是否正在运行。

回答by Martin

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_namewith the name of the process you are looking for (i.e. vlc).

替换process_name为您要查找的进程的名称(即vlc)。

回答by No Idea For Name

you can use either Process.GetProcessesByNameif you know the process name or Process.GetProcessesByIDif you know it's ID.

Process.GetProcessesByName如果您知道进程名称或Process.GetProcessesByID知道它的 ID,则可以使用。