views:

23

answers:

1

I have two Windows services, we'll call X and Y. X handles the general functionality for my application, and Y exists to keep X up to date. It does this by checking for updates to X. If they exist, it downloads them, shuts down X, copies in the new files, and restart X.

However, I'd like Y to do the same thing for X. My concern, though, is that it's possible for each service to shut each other down, meaning they never get restarted.

I can think of three solutions:

  1. Maintain a third service, Z, which is never updated, that only checks if each service has been shut down for more than a minute, and if so, restarts them. This wouldn't be a bad thing to have, anyway, but it seems like something that I'd like to be able to update, which introduces the original problem, again.
  2. Maintaining a lock in the registry, such that X checks if Y is updated before doing an update itself, and vice versa.
  3. Having each service start the other services in its OnStop method. This seems a bit hackish, though.

What is the proper solution to this problem?

A: 

I ended up using System.Threading.Mutex. Both services will always run on the same machine, so it's a super easy solution.

Mike Pateras