diff --git a/MediaBrowser.Mono.userprefs b/MediaBrowser.Mono.userprefs index f07c9fbcf0..1cbdc7c0a1 100644 --- a/MediaBrowser.Mono.userprefs +++ b/MediaBrowser.Mono.userprefs @@ -1,13 +1,13 @@  - + - + - - + + diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index d3b6bc59f0..9fb9010e53 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -44,13 +44,11 @@ namespace MediaBrowser.Server.Implementations.Session /// The configuration manager. private readonly IServerConfigurationManager _configurationManager; - private object _sessionLock = new object(); - /// /// The _active connections /// - private readonly Dictionary _activeConnections = - new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary _activeConnections = + new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); /// /// Occurs when [playback start]. @@ -86,7 +84,7 @@ namespace MediaBrowser.Server.Implementations.Session /// All connections. public IEnumerable Sessions { - get { return _activeConnections.Values.ToList().OrderByDescending(c => c.LastActivityDate); } + get { return _activeConnections.Values.OrderByDescending(c => c.LastActivityDate).ToList(); } } /// @@ -195,28 +193,18 @@ namespace MediaBrowser.Server.Implementations.Session { var key = clientType + deviceId + appVersion; - lock (_sessionLock) + var connection = _activeConnections.GetOrAdd(key, keyName => new SessionInfo { - SessionInfo connection; + Client = clientType, + DeviceId = deviceId, + ApplicationVersion = appVersion, + Id = Guid.NewGuid() + }); - if (!_activeConnections.TryGetValue(key, out connection)) - { - connection = new SessionInfo - { - Client = clientType, - DeviceId = deviceId, - ApplicationVersion = appVersion, - Id = Guid.NewGuid() - }; - - _activeConnections[key] = connection; - } + connection.DeviceName = deviceName; + connection.User = user; - connection.DeviceName = deviceName; - connection.User = user; - - return connection; - } + return connection; } /// @@ -589,4 +577,4 @@ namespace MediaBrowser.Server.Implementations.Session return Task.WhenAll(tasks); } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index fddf9706d0..2c2390a814 100644 --- a/MediaBrowser.Server.Mono/Program.cs +++ b/MediaBrowser.Server.Mono/Program.cs @@ -21,8 +21,6 @@ namespace MediaBrowser.Server.Mono { private static ApplicationHost _appHost; - private static Mutex _singleInstanceMutex; - private static ILogger _logger; private static MainWindow _mainWindow; @@ -45,18 +43,6 @@ namespace MediaBrowser.Server.Mono AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - bool createdNew; - - //_singleInstanceMutex = new Mutex(true, @"Local\" + runningPath, out createdNew); - createdNew = true; - - if (!createdNew) - { - _singleInstanceMutex = null; - logger.Info("Shutting down because another instance of Media Browser Server is already running."); - return; - } - if (PerformUpdateIfNeeded(appPaths, logger)) { logger.Info("Exiting to perform application update."); @@ -71,8 +57,6 @@ namespace MediaBrowser.Server.Mono { logger.Info("Shutting down"); - ReleaseMutex(logger); - _appHost.Dispose(); } } @@ -230,24 +214,6 @@ namespace MediaBrowser.Server.Mono } } - /// - /// Releases the mutex. - /// - internal static void ReleaseMutex(ILogger logger) - { - if (_singleInstanceMutex == null) - { - return; - } - - logger.Debug("Releasing mutex"); - - _singleInstanceMutex.ReleaseMutex(); - _singleInstanceMutex.Close(); - _singleInstanceMutex.Dispose(); - _singleInstanceMutex = null; - } - /// /// Performs the update if needed. /// @@ -278,24 +244,11 @@ namespace MediaBrowser.Server.Mono public static void Restart() { - // Second instance will start first, so release the mutex and dispose the http server ahead of time - ReleaseMutex (_logger); - + // Second instance will start first, so dispose so that the http ports will be available to the new instance _appHost.Dispose(); - if (trayIcon != null) { - trayIcon.Visible = false; - trayIcon.Dispose (); - trayIcon = null; - } - - if (_mainWindow != null) { - _mainWindow.HideAll (); - _mainWindow.Dispose (); - _mainWindow = null; - } - - Application.Quit (); + // Right now this method will just shutdown, but not restart + Shutdown (); } } }