如何暂停最顶层的进程? (最好用c#解决方案)
我将应用程序编写为主机应用程序之上的模块。让我们调用主机应用程序进程 A 和我的应用程序进程 B。进程 B 与进程 A 处于子关系。从进程 BI 启动另一个进程,将其称为 C,当进程 C 运行时,我希望 A 和 B 暂停。要从 BI 启动 C,请使用 Process 类,并阻止 B 调用 WaitForExit()。但如何也阻止 A。同样,当 C 运行时,A 和 B 应该暂停。
主机应用程序是第三方应用程序,因此我只能通过 API 进行访问。我正在考虑获取进程 B 的父进程(即 A),并为 A 中的每个线程调用它的 Suspend() 方法,但此方法已过时。有哪些优雅的方法可以实现我的目标?
我的主机应用程序是 SAP B1。
I have application written as a module on top of host app. Let's call host app process A and my app process B. Process B is in child relation to process A. From process B I start another process, called it C and while process C is running I want A and B to be suspended. To start C from B I use Process class and I block B calling WaitForExit(). But how to also block A. Again, while C is running A and B should be suspended.
Host app is third party app so I have only access through API. I was thinking about getting process' B parent process (which is A) and for every thread in A calling it's Suspend() method but this method is obsolete. What are the elegant ways to achive my goal?
My host app is SAP B1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅不推荐使用 .NET Thread.Suspend() 方法。这不是您想要在这里做的,您正在尝试暂停一个甚至可能不是托管的进程。无论哪种方式,您都可以调用 Windows SuspendThread() 函数。这需要线程句柄,从 OpenThread() 获取。这需要线程 ID,您可以从 .NET 的 ProcessThread 获取该 ID。
这是一把相当大的锤子,你应该避免挥动。只需禁用应用程序的主窗口(EnableWindow API 函数)就足够了,而且随机性要低得多。无论哪种方式都需要本机 API 技能,请访问 pinvoke.net 以获取您需要的声明。
Only the .NET Thread.Suspend() method is deprecated. Which is not what you want to do here, you are trying to suspend a process that probably isn't even a managed. Either way, you'd pinvoke the Windows SuspendThread() function. That requires the thread handle, get that from OpenThread(). That requires the thread ID, you can get that from .NET's ProcessThread.
This is all a rather big hammer, one you should avoid swinging. Just disabling the app's main window (EnableWindow API function) should be sufficient and far less random. Native API skills required either way, visit pinvoke.net for the declarations you need.