Is a timer or filewatcher more effecient when watching for a process to close

Viewed 46

I have two programs running. Program1.exe and Program2.exe.

Program1 is written in C# .Net4.8 and is used to upload/download transaction from the web, check for updates and handle various other tasks that Program2 cannot.

Program2 is written in VB6. Yeah, VB6... It's set for a rewrite but we aren't at that stage yet due to it's complexities. It is more of a use interface application.

When Program1 checks for updates and determines if there is one available. When Program2 shuts down, Program1 need to prompt the users that there is an update available and attempt to install it.

My issue is, how do I determine that Program2 has shut down to immediately prompt the user before they shut down the computer. I was thinking that Program2 creates a flag file and I watch for it with a filewatcher or I can put up a timer that checks if Program2 is running. I'm assuming I'll have to put the timer on 1 second intervals to catch it correctly.

Which is more efficient or is there a better way to handle this?

Any suggestions would be greatly appreciated.

1 Answers

Consider looking at it from a different perspective.

When Program2 shuts down, you could have it launch Program1 with a command line argument that tells it to check for updates. If no updates are available, Program1 shuts down silently. Otherwise, it prompts to apply the update and does so if allowed to.

Of course, this means adding command line parameter support to Program 1 (unless patching is all that it does).

But this way, you could run the patcher both before and after Program2 runs.

Related