System.Diagnostics.AsyncStreamReader.FlushMessageQueue C# (CSharp) Method

FlushMessageQueue() private method

private FlushMessageQueue ( ) : void
return void
        private void FlushMessageQueue() {            
            while(true) {
               
                // When we call BeginReadLine, we also need to flush the queue
                // So there could be a race between the ReadBuffer and BeginReadLine
                // We need to take lock before DeQueue.
                if( messageQueue.Count > 0) {
                    lock(messageQueue) {
                        if( messageQueue.Count > 0) {
                            string s = (string)messageQueue.Dequeue();
                            // skip if the read is the read is cancelled
                            // this might happen inside UserCallBack
                            // However, continue to drain the queue
                            if (!cancelOperation)
                            {
                                userCallBack(s);
                            }							
                        }
                    }
                }
                else {
                    break;
                }
            }
        }