Skip to content

Commit

Permalink
The mutex should be destroyed as late as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
synhershko committed Jul 30, 2012
1 parent 587e4c5 commit a8cc18d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/NAppUpdate.Framework/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static UpdateManager Instance
get { return instance; }
}
private static readonly UpdateManager instance = new UpdateManager();
private static Mutex _shutdownMutex;

#endregion

Expand Down Expand Up @@ -448,7 +449,7 @@ public void ApplyUpdates(bool relaunchApplication, bool updaterDoLogging, bool u
AppPath = ApplicationPath,
WorkingDirectory = Environment.CurrentDirectory,
RelaunchApplication = relaunchApplication,
LogItems = Logger.LogItems,
LogItems = Logger.LogItems,
};

NauIpc.ExtractUpdaterFromResource(Config.TempFolder, Instance.Config.UpdateExecutableName);
Expand Down Expand Up @@ -477,13 +478,11 @@ public void ApplyUpdates(bool relaunchApplication, bool updaterDoLogging, bool u
}

bool createdNew;
using (new Mutex(true, Config.UpdateProcessName + "Mutex", out createdNew))
{
if (NauIpc.LaunchProcessAndSendDto(dto, info, Config.UpdateProcessName) == null)
throw new UpdateProcessFailedException("Could not launch cold update process");
_shutdownMutex = new Mutex(true, Config.UpdateProcessName + "Mutex", out createdNew);
if (NauIpc.LaunchProcessAndSendDto(dto, info, Config.UpdateProcessName) == null)
throw new UpdateProcessFailedException("Could not launch cold update process");

Environment.Exit(0);
}
Environment.Exit(0);
}

State = UpdateProcessState.AppliedSuccessfully;
Expand Down
1 change: 1 addition & 0 deletions src/NAppUpdate.Updater/AppStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private static void Main()
var dto = NauIpc.ReadDto(syncProcessName) as NauIpc.NauDto;

// Make sure we start updating only once the application has completely terminated
Thread.Sleep(100); // hell, let's even wait a bit
bool createdNew;
using (var mutex = new Mutex(false, syncProcessName + "Mutex", out createdNew))
{
Expand Down

0 comments on commit a8cc18d

Please sign in to comment.