简体   繁体   English

如何检查外部WPF进程或其他进程是否已启动?

[英]How to check if external WPF process or other process is done launching?

I've written a WPF/C#-based "shell" which launches WPF apps or other apps. 我已经写了一个基于WPF / C#的“外壳”,它可以启动WPF应用程序或其他应用程序。

What would be the best method for checking if the process is finally fully launched or no longer "busy"? 检查该过程是否最终完全启动或不再“繁忙”的最佳方法是什么? I've noticed that the mouse cursor for the launched process stays at the busy cursor from initial launch until I can finally see the UI for the process. 我已经注意到,从初始启动开始,直到最终可以看到该进程的UI为止,已启动进程的鼠标光标一直位于繁忙光标处。 Could I use User32.SetCapture API to set the mouse capture to the external process, then somehow check if the mouse cursor is the busy cursor? 我可以使用User32.SetCapture API将鼠标捕获设置为外部进程,然后以某种方式检查鼠标光标是否为繁忙光标吗? Or perhaps there's a mechanism in the System.Diagnostics.Process class that I'm unaware of? 还是System.Diagnostics.Process类中存在我不知道的机制?

As some of the launched apps are pre-compiled third-party apps, I absolutely cannot implement a mechanism in the external processes to message if it is finally ready, such as: Microsoft PowerPoint 2010 Viewer, Adobe Acrobat, or Adobe Flash Player Standalone. 由于某些已启动的应用程序是预编译的第三方应用程序,因此我绝对不能在外部流程中实现某种机制,以告知消息是否终于准备就绪,例如:Microsoft PowerPoint 2010 Viewer,Adobe Acrobat或Adobe Flash Player Standalone。

I can't just check if the process has been created, because then I have a blank, unresponding window and a busy cursor. 我不能只检查是否已创建该进程,因为这样我将有一个空白,无响应的窗口和一个繁忙的光标。 I hope to hide my WPF app the moment the external process is done launching. 我希望在外部过程启动完成后隐藏我的WPF应用程序。

The WaitForInputIdle Win32 APi function will wait until given process enters the message loop (with no input pending). WaitForInputIdle Win32 APi函数将等待,直到给定进程进入消息循环(无输入挂起)。

Quote: "Before trying to communicate with the child process, the parent process can use the WaitForInputIdle function to determine when the child's initialization has been completed." Quote: “在尝试与子进程进行通信之前,父进程可以使用WaitForInputIdle函数来确定子进程的初始化何时完成。”

You can call it via P/Invoke. 您可以通过P / Invoke调用它。

Not very cear what do you mean saying "beasy", but hear are several considerations: 不太了解您所说的“轻松”是什么意思,但请注意以下几点:

There is no known (clear) way, at least that I'm aware of, that can let you do something like that. 至少我不知道,没有已知的(明确的)方法可以让您执行类似的操作。 The thing is that process is perfectly isolated OS kernel citizen. 关键是该process是完全隔离的OS内核公民。 So you can not write something that works for all type processes, especially if they are 3rd part binaries. 因此,您不能编写适用于所有类型进程的内容,特别是如果它们是第3部分二进制文件。

What you can try to do, is get the MainWindow of the process (if there is any), get its handle , and filter OS messages untill you get for example WM_ACTIVATED . 您可以尝试做的是获取进程的MainWindow (如果有),获取其handle并过滤OS消息,直到获得例如WM_ACTIVATED

But even if this could work in certain situations, in others can measurably fail. 但是,即使这可能在某些情况下工作,别人能可测量失败。 For example, process loaded but the program is not active, cause for some reason License window of the application appeared. 例如,进程已加载但程序未激活,由于某种原因导致出现了应用程序的“ License窗口。

Let's see what others suggest, in my opinion, there is no generic and no single solution to cover minority of possible cases. 在我看来,让我们看看其他人的建议,没有通用的解决方案,也没有单一的解决方案来涵盖少数可能的情况。

Good luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM