private void ReconnectCallback(object state) { BackoffTimeoutHelper helper = new BackoffTimeoutHelper(TimeSpan.MaxValue, TimeSpan.FromMinutes(5.0), TimeSpan.FromSeconds(30.0)); while (this.state == CommunicationState.Opening) { try { this.StartListen(true); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (DiagnosticUtility.ShouldTraceError) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error); } } if (this.state == CommunicationState.Opening) { helper.WaitAndBackoff(); } } }
private ServiceControllerStatus ExitServiceStatus(ServiceController service, int pollMin, int pollMax, ServiceControllerStatus status) { ServiceControllerStatus status2; BackoffTimeoutHelper helper = new BackoffTimeoutHelper(TimeSpan.MaxValue, TimeSpan.FromMilliseconds((double)pollMax), TimeSpan.FromMilliseconds((double)pollMin)); do { if (this.closed) { return(service.Status); } helper.WaitAndBackoff(); service.Refresh(); status2 = service.Status; }while (status2 == status); return(status2); }
public void Listen() { BackoffTimeoutHelper helper = new BackoffTimeoutHelper(TimeSpan.FromSeconds(1.0)); lock (this.ThisLock) { if (this.listenSocket != null) { this.listenSocket.Listen(this.settings.ListenBacklog); this.isListening = true; } while (!this.isListening) { try { this.listenSocket = new Socket(this.localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if ((this.localEndpoint.AddressFamily == AddressFamily.InterNetworkV6) && this.settings.TeredoEnabled) { this.listenSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPProtectionLevel, 10); } this.listenSocket.Bind(this.localEndpoint); this.listenSocket.Listen(this.settings.ListenBacklog); this.isListening = true; continue; } catch (SocketException exception) { bool flag = false; if ((exception.ErrorCode == 0x2740) && !helper.IsExpired()) { helper.WaitAndBackoff(); flag = true; } if (!flag) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ConvertListenException(exception, this.localEndpoint)); } continue; } } this.socketAsyncEventArgsPool = new SocketAsyncEventArgsPool(GetAcceptBufferSize(this.listenSocket)); } }