如何使用c#检查进程是否正在运行 [英] How to check whether a Process is running or not using c#

查看:90
本文介绍了如何使用c#检查进程是否正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







我想开发一个ac#程序来检查我的系统中的进程是否正在运行应该显示一个消息框,看看进程是否正在运行。



我已经尝试了下面的代码,但不幸的是它显示为进程没有始终运行,即使进程正在运行。



Hi,


I want to develop a c# program to check whether a process in my system is running or not and it should display a message box whether the process is running or not running.

I have tried the below code, but unfortunately it is showing as process not running always even when the process is running.

Process[] pname = Process.GetProcessesByName("VLC Player");
if (pname.Length > 0)
{
MessageBox.Show("Process Running");
}
else
{
MessageBox.Show("Process Not running");
}
System.Threading.Thread.Sleep(5 * 1000);





但是它始终显示为Process not running,默认情况下将pname.Length值设为Zero。请给我一些有价值的建议。



But always it is showing as Process not running, It is by default taking the pname.Length value as Zero. Please give me some valuable suggestions.

推荐答案

可能,这不是正确的名字。

在我的系统上,它是VLC媒体播放器( 32位),但是也找不到它。

我做的是使用调试器:

Probably, it's not the right name.
On my system, it's "VLC media player (32 bit)", but that doesn't find it either.
What I did was use the debugger:
Process[] pname = Process.GetProcesses();

快速查看列表给了我:

And a quick look through the list gave me:

Process[] pname = Process.GetProcessesByName("vlc");
if (pname.Length > 0)
    {
    MessageBox.Show("Process Running");
    }
else
    {
    MessageBox.Show("Process Not running");
    }

给出正确的消息框。


这篇关于如何使用c#检查进程是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆