等待资源完成

时间:2015-04-05 14:14:08

标签: c# visual-studio embedded-resource

我知道如何开始一个进程以及如何等待它退出但是它似乎无法正常运行资源。我有以下代码行

 string path = @"C:\Users\%USERNAME%\AppData\Local\Temp\MyFolder";
              Directory.CreateDirectory(path);

            if (checkbox1.Checked)
            {
                var exe1 = new Resource("SOLUTION.Resources.First.exe",
                Path.Combine(path, "1st.exe"));
                Process.Start(exe1.FilePath);

            }
            if (checkbox2.Checked)
            {
               var exe2 = new Resource("SOLUTION.Resources.Second.exe",
                Path.Combine(path, "Second.exe"));
                Process.Start(exe2.FilePath);
            }

但是当我开始这个过程时,他们两个一起开始如何设置他们每个人等待前一个完成?


感谢大家到目前为止的支持

1 个答案:

答案 0 :(得分:0)

您可以使用Process.WaitForExit()

string path = @"C:\Users\%USERNAME%\AppData\Local\Temp\MyFolder";
    Directory.CreateDirectory(path);

if (checkbox1.Checked)
{
    var exe1 = new Resource("SOLUTION.Resources.First.exe",
    Path.Combine(path, "1st.exe"));
    Process.Start(exe1.FilePath).WaitForExit();
}
if (checkbox2.Checked)
{
    var exe2 = new Resource("SOLUTION.Resources.Second.exe",
    Path.Combine(path, "Second.exe"));
    Process.Start(exe2.FilePath).WaitForExit();
}