views:

2971

answers:

5

Is there a framework that can be used to enable a C# Windows Service to automatically check for a newer version and upgrade itself? I can certainly write code to accomplish this, but I am looking for a framework that has already been implemented and (most importantly) tested.

A: 

Could you clarify your question a bit? I'm a bit confused, because as far as I know, you can always overwrite the DLLs the service uses. The copy and restart of the service can easily be made part of you build process.

Esteban Araya
Sorry for the confusion. I would like a way for my service to poll for updates and self install them when found. I have many services on many production (access controlled) servers and am very tired of the hastle and risk of manual interventions.
Larry Smithmier
+1  A: 

I'm not aware of any Frameworks that facilitate solutions to this specific problem.

What you could try though is separating the business logic of the service from the actual service code into different assemblies. Have the service assembly check for updates to the business logic assembly at regular intervals, copy it from a remote source if necessary, unload the old BL assembly (and perhaps delete), and then dynamically load the new version (unloading the old assembly is not a trivial task).

ilitirit
+4  A: 

The only way to unload types is to destroy the appdomain. To do this would require separation of your hosting layer from your executing service code - this is pretty complex. (sort of like doing keyhole surgery)

May be easier to either a) run a batch task or b) in-service detect updates then launch a seperate process that stops the service, updates assemblies etc. then restarts it.

If you're interested in the former, the MSDN patterns and practices folk wrote an app updater block that you adapt to your service.

http://msdn.microsoft.com/en-us/library/ms978574.aspx

stephbu
A: 

Another possible solution is to have a seperate service that runs, stops the other one, if there is an update, and then updates the service. You can't have a service update itself because the .dll that is running will not stop.

Seperating the business logic layer would be a good option. You could also rewrite the main service to run under reflection by a master or control service. This is similar to seperating the business logic, and it would just require stopping a thread and the starting it again.

I know of no known framework that does this. I have done this myself, but that is not a public framework.

David Basarab
+1  A: 

In case anyone else is searching for this; I found this link interesting. I have not implemented this solution, but it looks like it might work for me

http://www.eggheadcafe.com/articles/20041204.asp

rotard