开发者

How to suspend topmost process? (solution preferably in c#)

开发者 https://www.devze.com 2023-02-17 06:32 出处:网络
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 anoth

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消