private void ThrowIfPendingException() { Exception pendingException = Interlocked.Exchange<Exception>(ref _pendingException, null); if (pendingException != null) { throw new WebSocketException(WebSocketError.Faulted, pendingException); } }