fixes #166 - Multiple instance crash.
This commit is contained in:
parent
4a100452cf
commit
57dd61d209
|
@ -24,12 +24,27 @@ namespace MediaBrowser.ServerApplication
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The single instance mutex
|
||||||
|
/// </summary>
|
||||||
|
private static Mutex _singleInstanceMutex;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the entry point of the application.
|
/// Defines the entry point of the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
|
bool createdNew;
|
||||||
|
|
||||||
|
_singleInstanceMutex = new Mutex(true, @"Local\" + typeof(App).Assembly.GetName().Name, out createdNew);
|
||||||
|
|
||||||
|
if (!createdNew)
|
||||||
|
{
|
||||||
|
_singleInstanceMutex = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Look for the existence of an update archive
|
// Look for the existence of an update archive
|
||||||
var appPaths = new ServerApplicationPaths();
|
var appPaths = new ServerApplicationPaths();
|
||||||
var updateArchive = Path.Combine(appPaths.TempUpdatePath, Constants.MbServerPkgName + ".zip");
|
var updateArchive = Path.Combine(appPaths.TempUpdatePath, Constants.MbServerPkgName + ".zip");
|
||||||
|
@ -66,11 +81,6 @@ namespace MediaBrowser.ServerApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The single instance mutex
|
|
||||||
/// </summary>
|
|
||||||
private Mutex SingleInstanceMutex;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the logger.
|
/// Gets or sets the logger.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -107,15 +117,6 @@ namespace MediaBrowser.ServerApplication
|
||||||
/// <param name="e">A <see cref="T:System.Windows.StartupEventArgs" /> that contains the event data.</param>
|
/// <param name="e">A <see cref="T:System.Windows.StartupEventArgs" /> that contains the event data.</param>
|
||||||
protected override void OnStartup(StartupEventArgs e)
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
bool createdNew;
|
|
||||||
SingleInstanceMutex = new Mutex(true, @"Local\" + GetType().Assembly.GetName().Name, out createdNew);
|
|
||||||
if (!createdNew)
|
|
||||||
{
|
|
||||||
SingleInstanceMutex = null;
|
|
||||||
Shutdown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||||
LoadKernel();
|
LoadKernel();
|
||||||
|
|
||||||
|
@ -190,23 +191,26 @@ namespace MediaBrowser.ServerApplication
|
||||||
|
|
||||||
base.OnExit(e);
|
base.OnExit(e);
|
||||||
|
|
||||||
|
if (CompositionRoot != null)
|
||||||
|
{
|
||||||
CompositionRoot.Dispose();
|
CompositionRoot.Dispose();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Releases the mutex.
|
/// Releases the mutex.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ReleaseMutex()
|
private void ReleaseMutex()
|
||||||
{
|
{
|
||||||
if (SingleInstanceMutex == null)
|
if (_singleInstanceMutex == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleInstanceMutex.ReleaseMutex();
|
_singleInstanceMutex.ReleaseMutex();
|
||||||
SingleInstanceMutex.Close();
|
_singleInstanceMutex.Close();
|
||||||
SingleInstanceMutex.Dispose();
|
_singleInstanceMutex.Dispose();
|
||||||
SingleInstanceMutex = null;
|
_singleInstanceMutex = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user