コード例 #1
0
        public virtual async Task WriteAsync(HubMessage message)
        {
            await _writeLock.WaitAsync();

            try
            {
                // This will internally cache the buffer for each unique HubProtocol/DataEncoder combination
                // So that we don't serialize the HubMessage for every single connection
                var buffer = message.WriteMessage(Protocol);
                _connectionContext.Transport.Output.Write(buffer);

                Interlocked.Exchange(ref _lastSendTimestamp, Stopwatch.GetTimestamp());

                await _connectionContext.Transport.Output.FlushAsync();
            }
            finally
            {
                _writeLock.Release();
            }
        }