How to automatically update an application without ClickOnce?

后端 未结 5 1011
别那么骄傲
别那么骄傲 2020-11-29 23:05

For the project I am working on, I am not allowed to use ClickOnce. My boss wants the program to look \"real\" (with an installer, etc).

I have installed Visual Stud

5条回答
  •  执笔经年
    2020-11-29 23:50

    I think you should check the following project at codeplex.com http://autoupdater.codeplex.com/

    This sample application is developed in C# as a library with the project name “AutoUpdater”. The DLL “AutoUpdater” can be used in a C# Windows application(WinForm and WPF).

    There are certain features about the AutoUpdater:

    1. Easy to implement and use.
    2. Application automatic re-run after checking update.
    3. Update process transparent to the user.
    4. To avoid blocking the main thread using multi-threaded download.
    5. Ability to upgrade the system and also the auto update program.
    6. A code that doesn't need change when used by different systems and could be compiled in a library.
    7. Easy for user to download the update files.

    How to use?

    In the program that you want to be auto updateable, you just need to call the AutoUpdate function in the Main procedure. The AutoUpdate function will check the version with the one read from a file located in a Web Site/FTP. If the program version is lower than the one read the program downloads the auto update program and launches it and the function returns True, which means that an auto update will run and the current program should be closed. The auto update program receives several parameters from the program to be updated and performs the auto update necessary and after that launches the updated system.

      #region check and download new version program
      bool bSuccess = false;
      IAutoUpdater autoUpdater = new AutoUpdater();
      try
      {
          autoUpdater.Update();
          bSuccess = true;
      }
      catch (WebException exp)
      {
          MessageBox.Show("Can not find the specified resource");
      }
      catch (XmlException exp)
      {
          MessageBox.Show("Download the upgrade file error");
      }
      catch (NotSupportedException exp)
      {
          MessageBox.Show("Upgrade address configuration error");
      }
      catch (ArgumentException exp)
      {
          MessageBox.Show("Download the upgrade file error");
      }
      catch (Exception exp)
      {
          MessageBox.Show("An error occurred during the upgrade process");
      }
      finally
      {
          if (bSuccess == false)
          {
              try
              {
                  autoUpdater.RollBack();
              }
              catch (Exception)
              {
                 //Log the message to your file or database
              }
          }
      }
      #endregion
    

提交回复
热议问题