相关疑难解决方法(0)

创建进程时是否存在系统事件?

创建新进程时是否有任何事件.我正在编写检查某些进程的ac#应用程序,但我不想写一个无限循环来连续迭代所有已知进程.相反,我宁愿检查每个创建的进程,也可以遍历事件触发的所有当前进程.有什么建议?

        Process[] pArray;
        while (true)
        {
            pArray = Process.GetProcesses();

            foreach (Process p in pArray)
            {
                foreach (String pName in listOfProcesses)  //just a list of process names to search for
                {

                    if (pName.Equals(p.ProcessName, StringComparison.CurrentCultureIgnoreCase))
                    {
                       //do some stuff

                    }
                }
            }

            Thread.Sleep(refreshRate * 1000);
        }
Run Code Online (Sandbox Code Playgroud)

c# events process

13
推荐指数
1
解决办法
5256
查看次数

C#检测产生的进程

我正在编写一段c#代码,用于启动安装程序并在继续执行其他操作之前等待它返回.

我遇到某些安装程序出现问题,这些安装程序在安装实际完成之前返回原始进程的其他进程.有什么方法可以等到所有过程完成后?

为了澄清这里我遇到麻烦的情况:

  1. 启动Installer1
  2. Installer1生成/启动另一个安装程序(Installer2)
  3. 安装程序1返回
  4. 应用程序认为安装已完成但Installer2仍在运行.这会导致应用程序中的工作流问题.

这是我目前正在使用的代码:

// launch installer
Process process = windowsApplicationLauncher.LaunchApplication(_localFilePath);

// wait for process to return
do
{
    if (!process.HasExited)
    {
    }
}
while (!process.WaitForExit(1000));

if (process.ExitCode == 0)
{
    _fileService.MoveFile(_localFilePath, _postInstallFilePath);

    _notification.SetComplete(false);

    return true;
}
return false;
Run Code Online (Sandbox Code Playgroud)

c# installer process spawn

7
推荐指数
1
解决办法
1224
查看次数

标签 统计

c# ×2

process ×2

events ×1

installer ×1

spawn ×1