I've written a program that updates itself if it finds a newer version on a server but I'm finding it hard to implement cleanly.
Checking a remote server and downloading the file are easy enough but then what? It can't simply File.Copy("newversion.exe","myprogram.exe") because myprogram is running and the file is locked.
I do it by downloading two files newversion and update. myprogram then launches update and exits. update waits for two seconds, does the copy, then launches myprogram (which is now the updated version) and exits. myprogram looks for update when it starts and deletes it and newversion if it finds them. mypogram is now the new version with no files left laying around.
There must be a better way than this so what's the .net way for a program to update itself?
PS. Sorry if this question appears twice - I got a 'stack overflow is broken' page the first time I submitted it.