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
How to check if application is running
提问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_name
with 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.GetProcessesByName
if you know the process name or Process.GetProcessesByID
if you know it's ID.
Process.GetProcessesByName
如果您知道进程名称或Process.GetProcessesByID
知道它的 ID,则可以使用。