Home > Backend Development > C#.Net Tutorial > Detailed explanation of how to implement automatic update of c#Winform program (picture)

Detailed explanation of how to implement automatic update of c#Winform program (picture)

黄舟
Release: 2017-03-22 11:33:11
Original
2864 people have browsed it

This is also my first time to do automatic update of Winform program. I found the source code of automatic update online. Then I tried it myself for a long time based on some methods I saw on the Internet. In the end, I still made mistakes, so I spent money to let others HelpDebugging Successfully, the following is what I made for everyone to learn from. If there are any mistakes, please correct me

This is my first time to do automatic update of Winform program. I found it online. I got the source code of automatic update, and then I tried it for a long time based on some methods I saw on the Internet, but in the end I still made mistakes, so I spent money to ask others to help me debug it successfully. The following is what I made by myself, so that everyone can learn from it. ,If there are any mistakes, please correct me.

1. Since I publish automatic updates through the server's IIS, I manually copy the program to the directory of the IIS server before updating, and make some changes to the client. to automatically update normally. So the first step is to be unfamiliar with the IIS server (my system is Windows 8):

Follow the above method, click OK after selecting, the system will automatically add these contents, and then:

#After the website is established, put the written files that need to be updated into the file directory corresponding to the physical path you selected.

2. After the website is established, the next step is to find a way to update it, that is, update the file from the server to the client. As for the specific process and central idea, I will not go into details. There are many online.

3. The automatic source code download address cannot be found. If you need it, please leave your email and I will send it again.

4. Generate the automatic source code into class library, Then reference this class library in your main program , and put the two files in the picture below in the same folder as your main program:

5. When calling the main program, I place it before the login form. Since I cannot control whether the program needs to be updated, I need to create a process. It is to create a table in the database, including two fields

As shown above, the New field saves the latest version, and the Old field saves the previous version.

using Mulaolao.Forms;
using Mulaolao.Procedure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Mulaolao.Other;
using System.Threading;
using StudentMgr;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace Mulaolao
{
 static class Program
 {
  //private static Mutex mutex;
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main( )
  {
   Application.EnableVisualStyles( );
   Application.SetCompatibleTextRenderingDefault( false );
   //读取表
   DataTable da = SqlHelper.ExecuteDataTable( "SELECT * FROM R_UpdateforOrder" );
   string news = "", old = "";
   //如果表中没有任何数据,则直接登录,不用更新
    if (da.Rows.Count < 1)
   {
    //设置登录成功之后关闭登录窗体 显示主窗体
    Login lg = new Login( );
    lg.StartPosition = FormStartPosition.CenterScreen;
    lg.ShowDialog( );
    if (lg.DialogResult == DialogResult.OK)
    {
     Application.Run( new Form1( ) );
    }
    else
    {
     return;
    }
   }
   else
   {
    //如果表中的新版本和老版本一致,也不需要更新
     news = da.Rows[0]["New"].ToString( );
    old = da.Rows[0]["Old"].ToString( );
    if (news == old)
    {
     //设置登录成功之后关闭登录窗体 显示主窗体
     Login lg = new Login( );
     lg.StartPosition = FormStartPosition.CenterScreen;
     lg.ShowDialog( );
     if (lg.DialogResult == DialogResult.OK)
     {
      Application.Run( new Form1( ) );
     }
     else
     {
      return;
     }
    }
    else
    {
     //如果表中的新版本和老版本不一致 则需要把老版本更新成新版本 同时启动自动更新窗口
      SqlHelper.ExecuteNonQuery( "UPDATE R_UpdateforOrder SET Old=@Old", new SqlParameter( "@Old", news ) );
     System.Diagnostics.Process.Start( Application.StartupPath + @"\AutoUpdate.exe" );
    }
   }
   
  }
 }
}
Copy after login

The next step is the next step. After completion, the updated main program will automatically start.

6. Let’s talk about the main parameters in UpdateList.xml:

The following is the updated version (New field in the table) program I wrote. Place it on the client, in the version update folder in the third picture. Run this program every time before updating the server to update the latest version of the database:

The above content is I spent a lot of money to come up with a not very advanced method, but I can't help it. I have only recently entered the industry and have little experience. I can't come up with an advanced method. You are welcome to correct me in time. In fact, the main steps are: first establish the IIS server--> Create a new website--> Put the main program file, update file, and version update in the same folder--> The main program calls the update program (mainly to judge When to perform automatic updates) --> Configure the parameters in the automatic update file --> Build the version comparison table in the database --> Cover the program on the server before updating, and modify the content of the automatic update xml file. Run version update -->Wait for client to update itself

The above is the detailed content of Detailed explanation of how to implement automatic update of c#Winform program (picture). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template