Click here to Skip to main content
16,019,263 members
Home / Discussions / C#
   

C#

 
GeneralRe: Automatically Install Updated Application Version Pin
Luc Pattyn29-Aug-10 13:42
sitebuilderLuc Pattyn29-Aug-10 13:42 
GeneralRe: Automatically Install Updated Application Version Pin
phil.o29-Aug-10 21:21
professionalphil.o29-Aug-10 21:21 
GeneralRe: Automatically Install Updated Application Version Pin
PDTUM30-Aug-10 3:47
PDTUM30-Aug-10 3:47 
GeneralRe: Automatically Install Updated Application Version Pin
phil.o30-Aug-10 6:02
professionalphil.o30-Aug-10 6:02 
AnswerRe: Automatically Install Updated Application Version [modified] Pin
Sunil G30-Aug-10 3:11
Sunil G30-Aug-10 3:11 
GeneralRe: Automatically Install Updated Application Version Pin
PDTUM30-Aug-10 3:56
PDTUM30-Aug-10 3:56 
GeneralRe: Automatically Install Updated Application Version Pin
Sunil G30-Aug-10 18:13
Sunil G30-Aug-10 18:13 
AnswerRe: Automatically Install Updated Application Version Pin
Matthew Klein30-Aug-10 14:38
Matthew Klein30-Aug-10 14:38 
I use the following for my one EXE updating solution. It may not follow best practices, but it works.

The idea is that you rename your current exe to a temp file, rename your new exe to your "normal" filename, then restart the process. You can rename the exe while its running, but you don't delete it. Instaed, you delete the "old" exe during your next update (or after the restart) and that way its no longer loaded in memory.

void UpdateAndRestart()
{
    //Assumes you have already downloaded new exe to myNewExeLoc
    string myNewExeLoc = @"C:\My Folder\myNewExe.new";
    string myCurrentExe = System.Reflection.Assembly.GetExecutingAssembly().Location;
    string myBakExe = myCurrentExe + ".bak";

    if (System.IO.File.Exists(myBakExe))
        System.IO.File.Delete(myBakExe);

    System.IO.File.Move(myCurrentExe, myBakExe);
    System.IO.File.Move(myNewExeLoc, myCurrentExe);

    System.Diagnostics.Process newP = new System.Diagnostics.Process();
    newP.StartInfo.FileName = myCurrentExe;
    newP.StartInfo.Arguments = "/updated" //or whatever arguments you want to pass (not required)
    newP.Start();

    System.Environment.Exit(0);
}


Edit:
I should note that I use a System.Threading.Mutex to make sure that only one version of my program is running at a time, so I can be sure that when I delete the old filename that there isn't still a version loaded in memory. I also check for the "/updated" argument on startup and deconflict any issues with the Mutex if the other version still hasn't unloaded (to mitigate race-condition errors).
GeneralRe: Automatically Install Updated Application Version Pin
Luc Pattyn30-Aug-10 14:54
sitebuilderLuc Pattyn30-Aug-10 14:54 
GeneralRe: Automatically Install Updated Application Version Pin
Chuck O'Toole30-Aug-10 16:16
Chuck O'Toole30-Aug-10 16:16 
GeneralRe: Automatically Install Updated Application Version Pin
PDTUM30-Aug-10 16:51
PDTUM30-Aug-10 16:51 
GeneralRe: Automatically Install Updated Application Version Pin
Matthew Klein31-Aug-10 4:44
Matthew Klein31-Aug-10 4:44 
AnswerRe: Automatically Install Updated Application Version Pin
Matthew Klein31-Aug-10 8:27
Matthew Klein31-Aug-10 8:27 
GeneralRe: Automatically Install Updated Application Version Pin
PDTUM31-Aug-10 9:24
PDTUM31-Aug-10 9:24 
AnswerRe: Automatically Install Updated Application Version Pin
Matthew Klein31-Aug-10 10:24
Matthew Klein31-Aug-10 10:24 
QuestionCOM PORT SETTING THROUGH C# IDE Pin
venkat swaminathan29-Aug-10 7:40
venkat swaminathan29-Aug-10 7:40 
QuestionUIS Application\MainDialog.Designer.cs Pin
zhiyuan1629-Aug-10 5:19
zhiyuan1629-Aug-10 5:19 
AnswerRe: UIS Application\MainDialog.Designer.cs Pin
Luc Pattyn29-Aug-10 5:24
sitebuilderLuc Pattyn29-Aug-10 5:24 
GeneralRe: UIS Application\MainDialog.Designer.cs Pin
zhiyuan1629-Aug-10 5:31
zhiyuan1629-Aug-10 5:31 
GeneralRe: UIS Application\MainDialog.Designer.cs Pin
Dan Mos29-Aug-10 5:41
Dan Mos29-Aug-10 5:41 
GeneralRe: UIS Application\MainDialog.Designer.cs Pin
zhiyuan1629-Aug-10 5:45
zhiyuan1629-Aug-10 5:45 
GeneralRe: UIS Application\MainDialog.Designer.cs Pin
Dan Mos29-Aug-10 6:02
Dan Mos29-Aug-10 6:02 
GeneralRe: UIS Application\MainDialog.Designer.cs Pin
Luc Pattyn29-Aug-10 5:43
sitebuilderLuc Pattyn29-Aug-10 5:43 
QuestionA simple question. Persistence block in C# text editor? Pin
Fred 3429-Aug-10 3:50
Fred 3429-Aug-10 3:50 
AnswerRe: A simple question. Persistence block in C# text editor? Pin
Abhinav S29-Aug-10 4:10
Abhinav S29-Aug-10 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.