本文介绍了我需要在以下代码中进行哪些更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我只是在尝试检查某个特定程序是否正在运行,或者未使用以下代码.但是它始终显示"Not running".我犯了什么错误?请帮助我进行纠正.

Hi,
I was just trying to check a particular program is currently running or not using the following code.But it always showing "Not running".What is the mistake ihave done?Kindly help me to rectify it.

static void Main(string[] args)
{
    Process[] myProcesss;
    myProcesss = Process.GetProcesses();
    foreach (Process myProcess in myProcesss)
    {
        if (myProcess.ProcessName.ToUpper() == "C:\\MyWebServerroot\\ConsoleApplication7\\ConsoleApplication7\\bin\\Debug\\ConsoleApplication7.exe")
        {
            Console.WriteLine("Running");
        }
        else
        {
            Console.WriteLine("Not Running");
        }
    }
    Console.ReadLine();
}

推荐答案

String.Equals( myProcess.ProcessName, "...", StringComparison.OrdinalIgnoreCase );


foreach (Process myPro in myProcesss)
    {
        if (myPro.ProcessName.Equals("ConsoleApplication7.exe")
        {
            Console.WriteLine("Running");
        }
        else
        {
            Console.WriteLine("Not Running");
        }
    }



谢谢...



Thanks...


Process[] myProcesss;
           myProcesss = Process.GetProcesses();
           bool isRunning = false;
           foreach (Process myProcess in myProcesss)
           {
               if (myProcess.ProcessName.Equals("myProgramme",StringComparison.InvariantCultureIgnoreCase ))
               {
                   isRunning = true;
               }
           }
           string message = isRunning ? "Running" : "Not Running";
           MessageBox.Show(message);



显然,用MessageBox代替Console.WriteLine代替控制台应用程序,用myProgramme代替程序名称.

希望对您有帮助



obviously substitute MessageBox for Console.WriteLine for a console app and myProgramme for the name of your programme.

Hope this helps


这篇关于我需要在以下代码中进行哪些更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:45