I want my C# Windows Service to automatically update itself

Larry Smithmier picture Larry Smithmier · Sep 20, 2008 · Viewed 28k times · Source

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.

[edit] Here is a link to a similar question with links to modern projects that help accomplish this: Auto-update library for .NET?

Answer

stephbu picture stephbu · Sep 20, 2008

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.

https://web.archive.org/web/20080506103749/http://msdn.microsoft.com/en-us/library/ms978574.aspx