void AcceptIfNecessary(bool startAccepting) { if (IsAcceptNecessary) { lock (ThisLock) { while (IsAcceptNecessary) { IAsyncResult result = null; Exception unexpectedException = null; try { result = listener.BeginAccept(acceptCompletedCallback, null); } catch (CommunicationException exception) { DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (startAccepting) { // Since we're under a call to StartAccepting(), just throw the exception up the stack. throw; } if ((errorCallback == null) && !ExceptionHandler.HandleTransportExceptionHelper(exception)) { throw; } unexpectedException = exception; } if ((unexpectedException != null) && (errorCallback != null)) { errorCallback(unexpectedException); } if (result != null) { // don't block our accept processing loop if (result.CompletedSynchronously) { ActionItem.Schedule(scheduleAcceptCallback, result); } pendingAccepts++; } } } } }
public IAsyncResult BeginAccept(AsyncCallback callback, object state) { return(connectionListener.BeginAccept(callback, state)); }