. Net Remoting method for simple online upgrade (next: Restart EXE)

Source: Internet
Author: User

First, preface

The previous article used. Net Remoting technology to resolve the local versus server version and download the update package process.

This article is mainly to apply process, to realize the procedure of restarting the program.

Scenario Assumptions:

Revit2016 is loading a DLL with version 1.0.0.0. The server's update DLL version is 1.0.0.10.

After downloading, Revit2016 closes, the old DLL is deleted, the new DLL is copied to the path where the old DLL is located, and the Revit2016 is restarted.

Second, the Code

Insert the following code before the last 79-80 lines of the previous code:

                Bgk_update.reportprogress (" updating ");                               New Thread (new  ThreadStart (Update));                T.start ();

To execute the UPDATE function:

         Public voidUpdate () {stringExePath =string.            Empty; Process[] PS= Process.getprocessesbyname ("Revit"); foreach(Process PinchPS) {ExePath= P.mainmodule.filename.tostring ();//get the EXE path for the processP.kill (); Close the process}foreach(varModuleinchServerupdatefiles. Keys)//Delete the original module{System.Threading.Thread.Sleep (1* +); Do a delay, because the process response speed problem, may lead to error such as: Access Denied ... File or the application path has not been found System.IO.File.Delete (Path.Combine (config.dir, module+". DLL"));            Copy the new file to the folder in the old file} copydir (Config.tempdir, Config.dir); System.Diagnostics.Process.Start (ExePath);//Restart the EXE}

Copy the contents of a folder into another folder:

 Public Static voidCopydir (stringSrcpath,stringAimpath) {            Try            {                //check whether the destination directory ends with a directory split character if it is not added                if(Aimpath[aimpath.length-1] !=Path.directoryseparatorchar) Aimpath+=Path.directoryseparatorchar; //determine if the target directory exists and if it does not exist, create a new                if(!directory.exists (Aimpath))                Directory.CreateDirectory (Aimpath); //get a list of the files in the source directory, which is an array containing the files and directory paths//If you point to the file below the copy destination file and do not include the directory, use the following method                string[] FileList =Directory.GetFiles (Srcpath); //string[] fileList = directory.getfilesystementries (Srcpath); //traverse all files and directories                foreach(stringFileinchfileList) {                    //as directory processing, if this directory is present, recursively copy the files under the directory                    if(directory.exists (file)) copydir (file, Aimpath+path.getfilename (file)); //Otherwise, the direct copy file                    Elsefile.copy (File, Aimpath+ path.getfilename (file),true); }            }            Catch{Console.WriteLine ("can't copy!"); }        }

. Net Remoting method for simple online upgrade (next: Restart EXE)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.