如何在运行进程时保持父窗体的活动状态?

时间:2018-08-12 20:33:47

标签: c# winforms

您好,我的主要形式是运行一个命令行exe为我做一些事情。唯一的问题是,它正在做需要做的事情,我的父表单完全冻结,直到流程结束。

有什么方法可以在不冻结父窗体的情况下运行该过程,以便可以单击按钮等?谢谢,我在下面提供了用于运行该过程的代码。

        Process newprocess = new Process();
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = true;
        startInfo.UseShellExecute = false;
        startInfo.FileName = @"C:\tool.exe";
        startInfo.Arguments = "Some Arguments";
        newprocess.StartInfo = startInfo;
        newprocess.Start();

        newprocess.WaitForExit();

1 个答案:

答案 0 :(得分:0)

将问题中的代码放入称为“ buildReferringEntitySpecification(Filter<X> filter, SingularAttribute<? super ENTITY, OTHER> reference, SingularAttribute<OTHER, X> valueField)”的方法中,然后在事件处理程序中调用buildReferringEntitySpecification(Filter<Long> filter, SingularAttribute<Tournament, Prize> reference, SingularAttribute<Prize, Currency *(instead of Long)*> valueField)

如果您需要在事件中执行UI操作,请在该过程完成后使用async:

RunProcessAndWait()

如果您想使等待更加真正地异步-可能在这里不是必须的,但是为了完整起见,它将为您节省一个线程一段时间-SO问题referred to in the comments的答案显示了如何做这个。

相关问题