System.Net.FtpWebRequest.TimedSubmitRequestHelper C# (CSharp) Method

TimedSubmitRequestHelper() private method

private TimedSubmitRequestHelper ( bool isAsync ) : Stream
isAsync bool
return System.IO.Stream
        private Stream TimedSubmitRequestHelper(bool isAsync)
        {
            if (isAsync)
            {
                // non-null in the case of re-submit (recovery)
                if (_requestCompleteAsyncResult == null)
                    _requestCompleteAsyncResult = new LazyAsyncResult(null, null, null);
                return _connection.SubmitRequest(this, true, true);
            }

            Stream stream = null;
            bool timedOut = false;
            TimerThread.Timer timer = TimerQueue.CreateTimer(_timerCallback, null);
            try
            {
                stream = _connection.SubmitRequest(this, false, true);
            }
            catch (Exception exception)
            {
                if (!(exception is SocketException || exception is ObjectDisposedException) || !timer.HasExpired)
                {
                    timer.Cancel();
                    throw;
                }

                timedOut = true;
            }

            if (timedOut || !timer.Cancel())
            {
                _timedOut = true;
                throw ExceptionHelper.TimeoutException;
            }

            if (stream != null)
            {
                lock (_syncObject)
                {
                    if (_aborted)
                    {
                        ((ICloseEx)stream).CloseEx(CloseExState.Abort | CloseExState.Silent);
                        CheckError(); //must throw
                        throw new InternalException(); //consider replacing this on Assert
                    }
                    _stream = stream;
                }
            }

            return stream;
        }