Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Feb 24, 2021
1 parent d2421d3 commit 457c3e0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Application/ResearchDataManagementPlatform/RDMPMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void RDMPMainForm_Load(object sender, EventArgs e)
//delete the persistence file and try again
MessageBox.Show("Persistence file corrupt, application will restart without persistence");
_persistenceFile.Delete();
Application.Restart();
ApplicationRestarter.Restart();
}
}

Expand Down
52 changes: 52 additions & 0 deletions Rdmp.UI/ApplicationRestarter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace Rdmp.UI
{
public static class ApplicationRestarter
{

public static void Restart()
{
try
{
Application.Restart();
}
catch (Exception)
{
RestartImpl();
}
}

private static void RestartImpl()
{
string[] arguments = Environment.GetCommandLineArgs();

StringBuilder sb = new StringBuilder((arguments.Length - 1) * 16);
for (int argumentIndex = 1; argumentIndex < arguments.Length - 1; argumentIndex++)
{
sb.Append('"');
sb.Append(arguments[argumentIndex]);
sb.Append("\" ");
}
if (arguments.Length > 1)
{
sb.Append('"');
sb.Append(arguments[arguments.Length - 1]);
sb.Append('"');
}
ProcessStartInfo currentStartInfo = new ProcessStartInfo();
currentStartInfo.FileName = Path.ChangeExtension(Application.ExecutablePath, "exe");
if (sb.Length > 0)
{
currentStartInfo.Arguments = sb.ToString();
}
Application.Exit();
Process.Start(currentStartInfo);
}
}
}
2 changes: 1 addition & 1 deletion Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private void PostFixPipelines(PlatformDatabaseCreationOptions opts)
private void RestartApplication()
{
MessageBox.Show("Connection Strings Changed, the application will now restart");
Application.Restart();
ApplicationRestarter.Restart();
}

private void btnCreateNew_Click(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Rdmp.UI/Versioning/PatchingUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void btnAttemptPatching_Click(object sender, EventArgs e)
checksUI1.OnCheckPerformed(new CheckEventArgs("Patching Succesful", CheckResult.Success, null));

if (MessageBox.Show("Application will now restart", "Close?", MessageBoxButtons.YesNo) == DialogResult.Yes)
Application.Restart();
ApplicationRestarter.Restart();
}
catch (Exception exception)
{
Expand Down

0 comments on commit 457c3e0

Please sign in to comment.