user17997813
user17997813

Reputation:

How to detect when a process doesnt exist anymore?

Trying to find a way to get notified when a process doesn't exist anymore, other way than constantly checking for something like"if process exist".

Which options do i have?

Upvotes: 2

Views: 133

Answers (1)

Andreas Wenzel
Andreas Wenzel

Reputation: 24736

You can open a process with OpenProcess and use WaitForSingleObject on that process. The function WaitForSingleObject will return as soon as the target process no longer exists. However, you will have to have one thread in a constant wait state if you want your program to be immediately notified when the target process no longer exists.

An alternative would be to call RegisterWaitForSingleObject, which will automatically create a thread for you (or use an existing thread in the thread pool), which will wait on the process and will call the callback function that you specified, as soon as the target process no longer exists.

Upvotes: 4

Related Questions