创建新进程时是否有任何事件.我正在编写检查某些进程的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#代码,用于启动安装程序并在继续执行其他操作之前等待它返回.
我遇到某些安装程序出现问题,这些安装程序在安装实际完成之前返回原始进程的其他进程.有什么方法可以等到所有过程完成后?
为了澄清这里我遇到麻烦的情况:
这是我目前正在使用的代码:
// 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)