update shutdown

pull/702/head
Luke Pulverenti 9 years ago
parent f3c3c74d84
commit c94706d6ee

@ -179,6 +179,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer
private void OnWebSocketConnecting(WebSocketConnectingEventArgs args)
{
if (_disposed)
{
return;
}
if (WebSocketConnecting != null)
{
WebSocketConnecting(this, args);
@ -187,6 +192,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer
private void OnWebSocketConnected(WebSocketConnectEventArgs args)
{
if (_disposed)
{
return;
}
if (WebSocketConnected != null)
{
WebSocketConnected(this, args);
@ -331,6 +341,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
var httpRes = httpReq.Response;
if (_disposed)
{
httpRes.StatusCode = 503;
httpRes.Close();
return Task.FromResult(true);
}
var operationName = httpReq.OperationName;
var localPath = url.LocalPath;

@ -71,6 +71,8 @@ namespace MediaBrowser.Server.Implementations.ServerManager
/// <value>The web socket listeners.</value>
private readonly List<IWebSocketListener> _webSocketListeners = new List<IWebSocketListener>();
private bool _disposed;
/// <summary>
/// Initializes a new instance of the <see cref="ServerManager" /> class.
/// </summary>
@ -143,6 +145,11 @@ namespace MediaBrowser.Server.Implementations.ServerManager
/// <param name="e">The <see cref="WebSocketConnectEventArgs" /> instance containing the event data.</param>
void HttpServer_WebSocketConnected(object sender, WebSocketConnectEventArgs e)
{
if (_disposed)
{
return;
}
var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, _jsonSerializer, _logger)
{
OnReceive = ProcessWebSocketMessageReceived,
@ -164,6 +171,11 @@ namespace MediaBrowser.Server.Implementations.ServerManager
/// <param name="result">The result.</param>
private async void ProcessWebSocketMessageReceived(WebSocketMessageInfo result)
{
if (_disposed)
{
return;
}
//_logger.Debug("Websocket message received: {0}", result.MessageType);
var tasks = _webSocketListeners.Select(i => Task.Run(async () =>
@ -244,6 +256,11 @@ namespace MediaBrowser.Server.Implementations.ServerManager
throw new ArgumentNullException("dataFunction");
}
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
}
cancellationToken.ThrowIfCancellationRequested();
var connectionsList = connections.Where(s => s.State == WebSocketState.Open).ToList();
@ -301,6 +318,8 @@ namespace MediaBrowser.Server.Implementations.ServerManager
/// </summary>
public void Dispose()
{
_disposed = true;
Dispose(true);
GC.SuppressFinalize(this);
}

@ -555,9 +555,10 @@ namespace MediaBrowser.ServerApplication
private static void ShutdownWindowsApplication()
{
_logger.Info("Calling Application.Exit");
Application.Exit();
//_logger.Info("Calling Application.Exit");
//Application.Exit();
_logger.Info("Calling Environment.Exit");
Environment.Exit(0);
_logger.Info("Calling ApplicationTaskCompletionSource.SetResult");

Loading…
Cancel
Save