IProcess.IsSuspend

delphi package - easy access to kernel objects etc.
Post Reply
djsale
Posts: 21
Joined: Wed Dec 27, 2006 4:09 pm

IProcess.IsSuspend

Post by djsale »

Hi madshi,

is there a way to detect if an appliction is suspended (sth. like process('app.exe').IsSuspend)?
Is it dangerous to use process('app.exe').RESUME in a timer to make sure another app doesn't suspend my one?

thanks in advance!
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: IProcess.IsSuspend

Post by madshi »

djsale wrote:is there a way to detect if an appliction is suspended (sth. like process('app.exe').IsSuspend)?
Not in one call. But you can loop through the threads and call "IThread.IsSuspended" for each of the threads. Please don't ask "IsSuspended" on yourself, though! Cause that would suspend yourself. :shock: So you should do something like this:

Code: Select all

function IsProcessSuspended(process: IProcess) : boolean;
var i1 : integer;
begin
  result := true;
  with process.Threads do
    for i1 := 0 to ItemCount - 1 do
      if (Items[i1].ID <> GetCurrentThreadId) and (not Items[i1].IsSuspended) then begin
        result := false;
        break;
      end;
end;
This is written from the top of my head. Hope it will compile and run fine.
djsale wrote:Is it dangerous to use process('app.exe').RESUME in a timer to make sure another app doesn't suspend my one?
It's not that dangerous, if you don't ever suspend any of your own threads - and if there aren't any 3rd party components in your process which are creating their own threads and suspending them. However, calling Myself.Resume in a timer won't help much, cause the timer event will not fire, anymore, if your process actually gets suspended!
djsale
Posts: 21
Joined: Wed Dec 27, 2006 4:09 pm

Re: IProcess.IsSuspend

Post by djsale »

Thanks a lot for this great and explicitely explanation. The best way ever would be to disallow suspending via hooking (like disabling process terminate). But I don't have any idea how to do that at all...
Any hint would be highly appreciated!
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Well, just check out the HookProcessTermination demo. If you want to block SuspendThread instead of TerminateProcess, you just need to do a few changes. It's really not that difficult.
djsale
Posts: 21
Joined: Wed Dec 27, 2006 4:09 pm

Post by djsale »

Thanks a lot, i'll give this a try.
Post Reply