public void init() { this.m_delegate = new Connection(m_factory, false, m_factory.CreateFrameHandler()); var self = this; ConnectionShutdownEventHandler recoveryListener = (_, args) => { lock (self) { if (ShouldTriggerConnectionRecovery(args)) { try { self.BeginAutomaticRecovery(); } catch (Exception e) { // TODO: logging Console.WriteLine("BeginAutomaticRecovery() failed: {0}", e); } } } }; lock (this.m_eventLock) { this.ConnectionShutdown += recoveryListener; if (!this.m_recordedShutdownEventHandlers.Contains(recoveryListener)) { this.m_recordedShutdownEventHandlers.Add(recoveryListener); } } }
///<summary>Broadcasts notification of the final shutdown of the connection.</summary> public void OnShutdown() { ConnectionShutdownEventHandler handler; ShutdownEventArgs reason; lock (m_eventLock) { handler = m_connectionShutdown; reason = m_closeReason; m_connectionShutdown = null; } if (handler != null) { foreach (ConnectionShutdownEventHandler h in handler.GetInvocationList()) { try { h(this, reason); } catch (Exception e) { CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e); args.Detail["context"] = "OnShutdown"; OnCallbackException(args); } } } AppDomain.CurrentDomain.DomainUnload -= HandleDomainUnload; }
///<summary>Broadcasts notification of the final shutdown of the connection.</summary> public void OnShutdown() { ConnectionShutdownEventHandler shutdownHandler; ShutdownEventArgs reason; lock (m_eventLock) { shutdownHandler = m_connectionShutdown; reason = m_closeReason; m_connectionShutdown = null; } RaiseEvent(shutdownHandler, reason); AppDomain.CurrentDomain.DomainUnload -= HandleDomainUnload; ConnectionShutdownEventHandler afterShutdownHandler; lock (m_eventLock) { afterShutdownHandler = m_afterConnectionShutdown; reason = m_closeReason; m_afterConnectionShutdown = null; } RaiseEvent(afterShutdownHandler, reason); }
///<summary>Broadcasts notification of the final shutdown of the connection.</summary> public void OnShutdown() { ConnectionShutdownEventHandler handler; ShutdownEventArgs reason; lock (m_eventLock) { handler = m_connectionShutdown; reason = m_closeReason; m_connectionShutdown = null; } if (handler != null) { foreach (ConnectionShutdownEventHandler h in handler.GetInvocationList()) { try { h(this, reason); } catch (Exception e) { CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e); args.Detail["context"] = "OnShutdown"; OnCallbackException(args); } } } AppDomain.CurrentDomain.DomainUnload -= HandleDomainUnload; }