. Net remoting Method for simple online upgrade (next article: restart exe),. netremoting

Source: Internet
Author: User

. Net remoting Method for simple online upgrade (next article: restart exe),. netremoting

I. Preface

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

This article mainly applies Process to restart the program.

ScenarioHypothesis:

Revit2016 is loading a dll whose version is 1.0.0.0. The server's latest dll version is 1.0.0.10.

After downloading, disable Revit2016, delete the old dll, copy the new dll to the path of the old dll, and restart Revit2016.

Ii. Code

Insert the following code before line 79-80 of the last code in the previous article:

Bgk_Update.ReportProgress (100, "Updating"); Thread t = new Thread (new ThreadStart (Update); t. Start ();

Execute the Update function:

Public void Update () {string exepath = string. empty; Process [] ps = Process. getProcessesByName ("Revit"); foreach (Process p in ps) {exepath = p. mainModule. fileName. toString (); // obtain the exe path of the process p. kill (); // close this process} foreach (var module in serverupdatefiles. keys) // Delete the original module {System. threading. thread. sleep (1*1000); // make a delay, because the process response speed is slow, it may cause an error such as: Access denied... file or the application path System is not found. IO. file. delete (Path. combine (Config. dir, module + ". dll "); // copy the new file to the folder of the old file} CopyDir (Config. tempDir, Config. dir); System. diagnostics. process. start (exepath); // restart the exe}

Copy the content of a folder to another folder:

Public static void CopyDir (string srcPath, string aimPath) {try {// check whether the target directory ends with a directory delimiter. if not, add the if (aimPath [aimPath. length-1]! = Path. DirectorySeparatorChar) aimPath + = Path. DirectorySeparatorChar; // if (! Directory. exists (aimPath) Directory. createDirectory (aimPath); // obtain the file list of the source directory, this is an array containing files and Directory paths. // if you point to a file under the copy target file and do not include a Directory, use the following method string [] fileList = Directory. getFiles (srcPath); // string [] fileList = Directory. getFileSystemEntries (srcPath); // traverses all files and directories. foreach (string file in fileList) {// first, it is processed as a Directory. if this Directory exists, recursively Copy the files under this Directory if (Directory. exists (file) CopyDir (file, aimPath + Path. getFileName (fi Le); // otherwise, Copy the else File directly. copy (file, aimPath + Path. getFileName (file), true) ;}} catch {Console. writeLine ("cannot be copied! ");}}

 

Related Article

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.