本文介绍了如何知道 Process.Start 何时加载 winform?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WindowsForm (c# .net 3.5) 中,点击一个按钮,使用 Process.Start() 启动另一个外部应用程序(也是 .net 3.5),并了解它在我启动后何时可用.

I'm in a WindowsForm (c# .net 3.5) and on click of a button launch another external application (also .net 3.5) using Process.Start() and understand when it is available after i have launched it.

    ProcessStartInfo psInfo = new ProcessStartInfo(@"MyApplication.exe");
psInfo.RedirectStandardOutput = true;
psInfo.RedirectStandardError = true;
psInfo.UseShellExecute = false;
psInfo.CreateNoWindow = true;
Process proc = Process.Start(psInfo);

proc... IsFullyLoaded()?

我该怎么做?

推荐答案

要等待进程创建其表单,请调用 WaitForInputIdle 方法.

To wait for the process to create its form, call the WaitForInputIdle method.

要了解它是否准备就绪,请尝试以下操作:

To find out whether it's ready, try this:

bool isReady = proc.WaitForInputIdle(0);

或者,或者,

bool isReady = (proc.MainWindowHandle != IntPtr.Zero);

您还可以使用 MainWindowHandle 属性通过 SendMessage API 函数

You can also use the MainWindowHandle property to send messages to the form using the SendMessage API function

这篇关于如何知道 Process.Start 何时加载 winform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:17