I am trying to write an automation software to execute certain things when different processes are started and then do another thing when they are closed.
I have successfully gotten this to work using ManagementEventWatcher. This, however, uses WMI in Windows, which in turn causes WMI Provider Host to use ~4% of the CPU. I find this to be a little excessive.
Is there a way to do what I want without the extreme CPU overhead?
Thanks
ManagementEventWatcheris a good decoupled fire-and-forget way to do it, but it can be a bit intensive. A less intensive but more "manual" way to do it would just be to get the list of processes every couple seconds and search for the process you're looking for. If you have access to the other program, the least intensive solution would be to send a message from the other program to your program indicating it's started, and pass the process ID. This can be done in a lot of ways. The most common are anonymous pipes (windows only) or TCP/UDP sockets.