Example #1
0
        private Task StartTransport()
        {
            return(_transport.Start(this, _connectionData, _disconnectCts.Token)
                   .RunSynchronously(() =>
            {
                // NOTE: We have tests that rely on this state change occuring *BEFORE* the start task is complete
                ChangeState(ConnectionState.Connecting, ConnectionState.Connected);

                // Now that we're connected complete the start task that the
                // receive queue is waiting on
                _startTcs.SetResult(null);

                // Start the monitor to check for server activity
                _monitor.Start();
            })
                   // Don't return until the last receive has been processed to ensure messages/state sent in OnConnected
                   // are processed prior to the Start() method task finishing
                   .Then(() => _lastQueuedReceiveTask));
        }
        private Task StartTransport()
        {
            return(_transport.Start(this, _connectionData, _disconnectCts.Token)
                   .RunSynchronously(() =>
            {
                ChangeState(ConnectionState.Connecting, ConnectionState.Connected);

                // Now that we're connected drain any messages within the buffer
                // We want to protect against state changes when draining
                lock (_stateLock)
                {
                    _connectingMessageBuffer.Drain();
                }

                if (_keepAliveData != null && _transport.SupportsKeepAlive)
                {
                    // Start the monitor to check for server activity
                    _monitor.Start();
                }
            }));
        }