c# - 为什么我创建的列表中没有名称的特定过程?

标签 c#

我有这个功能可以检查进程是否启动以及何时退出。 但是我在 IF 上的断点上使用并且列表计数始终为 0。

当我运行任务管理器时,我看到了 bf3.exe *32 那么这里出了什么问题?

private void isProcessRunning()
{                
    Process[] proclist = Process.GetProcessesByName("bf3.exe");

    if (proclist.Length > 0)
    {
        Logger.Write("Battlefield 3 Started");
        alreadyRun = true;
    }
    else if (alreadyRun == true)
    {
        Logger.Write("Battlefield 3 Exited");
    }            
}

最佳答案

来自documentation :

The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path. GetProcessesByName is helpful for getting and manipulating all the processes that are associated with the same executable file. For example, you can pass an executable file name as the processName parameter, in order to shut down all the running instances of that executable file.

强调我的。

关于c# - 为什么我创建的列表中没有名称的特定过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12204914/

相关文章:

c#根据下载请求动态重命名文件

c# - 将类属性转换为字符串列表

c# - 用于单元测试的模拟 gRPC 响应流 - C#

c# - 如何清除/删除文件 licenses.licx

c# - 在unity 3D编辑器中获取右键单击的路径

c# - 无法将类型 int[] 隐式转换为 int?[]

C# MVC Controller 调用两次

c# - 当您将文本转换设置为大写的链接时,LinkText 不起作用

c# - 使用 C# 和 MySQL 的 Crystal 报表。正在设计但运行时总是登录失败

c# - 在 Windows 应用商店应用程序中垂直对齐 ListBox 的内容