Skip to content

Commit

Permalink
Disposed mutex and improved exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgTrade committed Apr 4, 2015
1 parent 1d9615e commit db6e060
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions nUpdate.Administration/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace nUpdate.Administration
{
public static class Program
{
private static Mutex _mutex;

/// <summary>
/// The path of the languages directory.
/// </summary>
Expand All @@ -28,18 +30,19 @@ public static class Program
private static void Main(string[] args)
{
bool firstInstance;
new Mutex(true, "MainForm", out firstInstance);
_mutex = new Mutex(true, "MainForm", out firstInstance);

if (!firstInstance)
return;

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += UnhandledException;
Application.ThreadException += UnhandledThreadException;
//currentDomain.UnhandledException += UnhandledException;
//Application.ThreadException += UnhandledThreadException;
Application.ApplicationExit += Exit;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
ExceptionlessClient.Current.Register();
ExceptionlessClient.Default.Register();

var dialog = new MainDialog();
if (args.Length == 1)
Expand All @@ -52,41 +55,39 @@ private static void Main(string[] args)
Application.Run(dialog);
}

private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
private static void Exit(object sender, EventArgs e)
{
Popup.ShowPopup(SystemIcons.Error, "nUpdate has just noticed an unhandled error.",
((Exception)e.ExceptionObject), PopupButtons.Ok);
var eventBuilder = ((Exception) e.ExceptionObject).ToExceptionless();
var nUpdateVersion = Assembly.GetExecutingAssembly()
.GetCustomAttributes(false)
.OfType<nUpdateVersionAttribute>()
.SingleOrDefault();
if (nUpdateVersion != null)
eventBuilder.SetVersion(
nUpdateVersion
.VersionString);
eventBuilder.MarkAsCritical().Submit();
ExceptionlessClient.Default.ProcessQueue();
Application.Exit();
if (_mutex != null)
_mutex.Dispose();
}

private static void UnhandledThreadException(object sender, ThreadExceptionEventArgs e)
{
Popup.ShowPopup(SystemIcons.Error, "nUpdate has just noticed an unhandled error.",
e.Exception, PopupButtons.Ok);
var eventBuilder = e.Exception.ToExceptionless();
var nUpdateVersion = Assembly.GetExecutingAssembly()
.GetCustomAttributes(false)
.OfType<nUpdateVersionAttribute>()
.SingleOrDefault();
if (nUpdateVersion != null)
eventBuilder.SetVersion(
nUpdateVersion
.VersionString);
eventBuilder.MarkAsCritical().Submit();
ExceptionlessClient.Default.ProcessQueue();
Application.Exit();
}
//private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
//{
// HandleException((Exception)e.ExceptionObject);
//}

//private static void UnhandledThreadException(object sender, ThreadExceptionEventArgs e)
//{
// HandleException(e.Exception);
//}

//private static void HandleException(Exception ex)
//{
// Popup.ShowPopup(SystemIcons.Error, "nUpdate has just noticed an unhandled error.",
// (ex), PopupButtons.Ok);
// var eventBuilder = (ex).ToExceptionless();
// var nUpdateVersion = Assembly.GetExecutingAssembly()
// .GetCustomAttributes(false)
// .OfType<nUpdateVersionAttribute>()
// .SingleOrDefault();
// if (nUpdateVersion != null)
// eventBuilder.SetVersion(
// nUpdateVersion
// .VersionString);
// eventBuilder.MarkAsCritical().Submit();
// ExceptionlessClient.Default.ProcessQueue();
// Application.Exit();
//}

/// <summary>
/// The root path.
Expand Down Expand Up @@ -121,7 +122,7 @@ public static string StatisticServersFilePath
/// </summary>
public static string VersionString
{
get { return "nUpdate Administration 1.0.0.0 Beta 1"; }
get { return "nUpdate Administration 1.0.0.0 Beta 2"; }
}

public static string AesKeyPassword
Expand Down

0 comments on commit db6e060

Please sign in to comment.