private async Task InternalRun() { try { while (auditor == null && !isAborted) { var _auditor = new AuditorWebSocketConnection(new ClientWebSocket(), null); try { Subscribe(_auditor); await _auditor.EstablishConnection(); auditor = _auditor; } catch (Exception exc) { Unsubscribe(_auditor); await CloseConnection(_auditor); if (!(exc is OperationCanceledException)) { logger.Info(exc, "Unable establish connection. Retry in 5000ms"); } Thread.Sleep(5000); } } } catch (Exception exc) { logger.Error(exc, "Auditor startup error."); Global.AppState.State = ApplicationState.Failed; } }
private void InternalRun() { var runTask = Task.Factory.StartNew(async() => { try { while (!isAborted) { var _auditor = new AuditorWebSocketConnection(Context, connectionFactory()); try { Subscribe(_auditor); await _auditor.EstablishConnection(); auditor = _auditor; break; } catch (Exception exc) { Unsubscribe(_auditor); await CloseConnection(_auditor); if (!(exc is OperationCanceledException)) { logger.Info(exc, "Unable establish connection. Retry in 5000ms"); } Thread.Sleep(5000); } } } catch (Exception exc) { logger.Error(exc, "Auditor startup error."); Context.AppState.State = ApplicationState.Failed; } }).Unwrap(); }