Skip to content

Commit

Permalink
adds a process id to the NauDto. the updater checks if the process is…
Browse files Browse the repository at this point in the history
… running and kills the process after 1,5 seconds (waiting for mutex has some problems under windows XP)
  • Loading branch information
phillipp committed Dec 12, 2012
1 parent acfbb69 commit a14325d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/NAppUpdate.Framework/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ public void ApplyUpdates(bool relaunchApplication, bool updaterDoLogging, bool u
WorkingDirectory = Environment.CurrentDirectory,
RelaunchApplication = relaunchApplication,
LogItems = Logger.LogItems,
ProcessId = Process.GetCurrentProcess().Id
};

NauIpc.ExtractUpdaterFromResource(Config.TempFolder, Instance.Config.UpdateExecutableName);
Expand Down
1 change: 1 addition & 0 deletions src/NAppUpdate.Framework/Utils/NauIpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class NauDto
public string AppPath { get; set; }
public string WorkingDirectory { get; set; }
public bool RelaunchApplication { get; set; }
public int ProcessId { get; set; }
}

[DllImport("kernel32.dll", SetLastError = true)]
Expand Down
23 changes: 22 additions & 1 deletion src/NAppUpdate.Updater/AppStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ private static void Main()
}
}

WaitForProcessTerminate(dto);

bool updateSuccessful = true;

if (dto == null || dto.Configs == null)
Expand Down Expand Up @@ -220,7 +222,26 @@ private static void Main()
}
}

private static void SelfCleanUp(string tempFolder)
private static void WaitForProcessTerminate(NauIpc.NauDto dto) {
try {
if (dto != null) {
int i = 0;
do {
Process.GetProcessById(dto.ProcessId);
Log("Process {0} still running...", dto.ProcessId);
i++;
Thread.Sleep(500);
} while (i <= 3);
Log("Killing process {0}...", dto.ProcessId);
Process.GetProcessById(dto.ProcessId).Kill();
}
}
catch (Exception) {
// parent process has exited
}
}

private static void SelfCleanUp(string tempFolder)
{
// Delete the updater EXE and the temp folder
Log("Removing updater and temp folder... {0}", tempFolder);
Expand Down

0 comments on commit a14325d

Please sign in to comment.