我正在编写一段 c# 代码来启动安装程序并等待它返回,然后再继续其他内容。
我在安装某些安装程序时遇到问题,这些安装程序会在安装实际完成之前生成其他进程,原始进程返回。有什么方法可以等到所有流程都完成?
为了澄清这是我遇到问题的场景:
- 启动安装程序1
- Installer1 产生/启动另一个安装程序 (Installer2)
- 安装程序 1 返回
- 应用程序认为安装已完成,但 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;