protected override void Dispose(bool disposing) { if (useEvents) { connection.MessageArrived -= ProcessMessage; if (connection is not LocalServiceHubConsumer) { connection.OperationalChanged -= ConnectivityChanged; } } connection.Dispose(); base.Dispose(disposing); }
private void TryReconnect(object state) { if (Monitor.TryEnter(reconnLock)) { try { if (hubClient != null && !hubClient.Operational) { try { hubClient.MessageArrived -= ClientInvokation; if (hubClient is not LocalServiceHubConsumer) { hubClient.OperationalChanged -= ConnectedChanges; } hubClient.Dispose(); } catch (Exception ex) { LogEnvironment.LogDebugEvent($"Un-Expected Disconnection Error: {ex.OutlineException()}", LogSeverity.Error); } finally { hubClient = null; } } if (hubClient == null) { try { ConnectToHub(); } catch (Exception ex) { LogEnvironment.LogEvent($"Error when connecting to hub: {ex.OutlineException()}", LogSeverity.Warning); } } else { reconnector.Change(Timeout.Infinite, Timeout.Infinite); } } finally { Monitor.Exit(reconnLock); } } }
public override void Dispose() { base.Dispose(); hubClient?.Dispose(); hubClient = null; reconnector.Dispose(); }
/// <summary> /// Tests the connection to the given target-proxy object /// </summary> /// <returns>a value indicating whether the connection is OK</returns> protected override bool Test() { if (connected || !initCalled) { if (!connection.Initialized) { try { connection.Initialize(); if (isBidirectional != IsBidirectional) { throw new Exception("Failed to Register return-channel. Check permissions on server."); } } finally { initCalled = true; } } if (!connection.Operational) { ConnectivityChanged(null, null); return(connected = false); } return(connected = connection.DiscoverService(targetService)); } else { try { ReConnectClient(); //return Test(); } catch { connection?.Dispose(); connection = null; connected = false; } } return(false); }