Good day.

There is a working application myapp.exe which downloads a new version from the server and puts it next to myapp.exe under the name. myapp.update.

How can I replace myapp.exe with a new myapp.exe?

Tried to make an additional project.

At the end the main project performs

Updater.MainWindow update = new Updater.MainWindow(); update.Show(); System.Diagnostics.Process.GetCurrentProcess().Kill(); 

But the main project window remains open but in the frieze.

The project in which Update is registered does not appear until the last action and closes immediately

  public MainWindow() { InitializeComponent(); Thread.Sleep(5000); UpdateNow(); } public void UpdateNow() { bool oldapp = false; bool newapp = false; Changes.Content = "Идет проверка целостности файлов..."; string path = System.IO.Directory.GetCurrentDirectory(); string[] allFoundFiles = Directory.GetFiles(path, "myapp.exe"); foreach (string file in allFoundFiles) { oldapp = true; } string[] allFoundFiles1 = Directory.GetFiles(path, "myapp.update"); foreach (string file in allFoundFiles) { newapp = true; } if (oldapp == true && newapp == true) { Changes.Content = "Все файлы на месте. Идет применение настроек..."; Thread.Sleep(5000); try { FileInfo fi1 = new FileInfo(path + @"\myapp.exe"); fi1.Delete(); } catch (Exception ex) { Changes.Content = ex.ToString(); } try { System.IO.File.Move(path + @"\myapp.update", path + @"\myapp.exe"); Changes.Content = "Все готово к работе :)"; System.Diagnostics.Process.Start(path + @"/myapp.exe"); } catch (Exception ex) { Changes.Content = ex.ToString(); } } else { Changes.Content = "Что - то не так"; } } } 

Not only that Update does not give signs of life. The "Access Denied" error appears when deleting the old myapp.exe. And why it closes by itself.

  • as an option in the closing project, use the common with the project dll, which will correctly close the program - user2455111

2 answers 2

For example, you can write a small application that copies myapp.update into myapp.update and run it before exiting the main application. Let the auxiliary application wait until the main one completes the work, and then transfers it.

    In fact, you can start another process, which after completing this will replace the file, but a more logical option is to have your program run through a "launcher" that will take and launch the latest version of the program that it finds in the folder.