title: Detecting a "Busy" WebSocket
body: <p>I recently ran into a problem with trying to broadcast to an open WebSocket using the SendAsync method, receiving an InvalidOperationException with the message "A send operation is already in progress"</p>
  
  <p>Digging through the source code for the WebSocket class, a busy state is tracked internally:</p>
  
  <pre><code>internal ChannelState _sendState;
  
  // Represents the state of a single channel; send and receive have their own states
  internal enum ChannelState {
      Ready, // this channel is available for transmitting new frames
      Busy, // the channel is already busy transmitting frames
      Closed // this channel has been closed
  }
  </code></pre>
  
  <p>Ideally, if I'm about to broadcast an update to a WebSocket connection, I'd like to know ahead of time that it's busy and perform some other handling (e.g. queue the message).</p>
  
  <p>It seems odd that this state is marked as internal -- were it a public property I could simply check for</p>
  
  <pre><code>context.WebSocket.SendState == ChannelState.Ready
  </code></pre>
  
  <p>What is the correct pattern to SendAsync on a WebSocket that would prevent throwing this exception?</p>
  
  <p>I'm loath to hack access to that property through reflection.</p>
  
  <p>Edit to clarify:</p>
  
  <p>The WebSocket.State property will not help this situation.  The property uses this enumeration:</p>
  
  <pre><code>public enum WebSocketState
  {
      None,
      Connecting,
      Open,
      CloseSent,
      CloseReceived,
      Closed,
      Aborted
  }
  </code></pre>
  
  <p>Once the socket connection has been opened, this statement will evaluate to "true" regardless of whether or not it is busy sending:</p>
  
  <pre><code>context.WebSocket.State == WebSocketState.Open
  </code></pre>