从C#应用程序中链接进程

时间:2012-07-12 13:09:00

标签: c# process installer .net chain

我需要创建一个Windows安装程序(可选)链接到另一个安装程序。我理解Visual Studio安装项目不允许这样做,所以我试图通过编写一个伞形应用程序来按顺序启动每个安装程序来处理这个问题(这也允许我允许用户选择要运行的安装程序)

问题是它们并行发射。如何抑制这种情况,以便第二次只在第一次终止后启动?

这是我的尝试:

        foreach (int item in installerList.CheckedIndices)
        {
            string procName = installerList.Items[item].ToString();
            string procPath="";
            //get the installer path corresponding to the checked item
            var proc = procList.FirstOrDefault(i => i.Item1 == procName);
            if (proc != null)
            {
                procPath = proc.Item2;

                Process installProc = new Process();
                installProc.StartInfo.FileName = procPath;
                installProc.StartInfo.UseShellExecute = false;
                installProc.Start();
                installProc.WaitForExit(); //don't start the next process until this one has completed or been closed
                do
                {
                } while (!installProc.HasExited);
                //if the process  did not terminate normally, cancel all further processes:
                if (installProc.ExitCode != 0)
                    break;
            }
        }

我错过了什么?

TIA

0 个答案:

没有答案