@@ -77,10 +77,10 @@ public class SharedQueue: IDisposable {
77
77
public SharedQueue ( ) {
78
78
}
79
79
80
- ///<summary>Close the queue. Causes all waiting threads to be
81
- ///interrupted (with EndOfStreamException) and all further
82
- ///Enqueue() and Dequeue() operations to throw
83
- ///EndOfStreamException.</summary>
80
+ ///<summary>Close the queue. Causes all further Enqueue()
81
+ ///operations to throw EndOfStreamException, and all pending
82
+ ///or subsequent Dequeue() operations to throw an
83
+ ///EndOfStreamException once the queue is empty .</summary>
84
84
public void Close ( ) {
85
85
lock ( m_queue ) {
86
86
m_isOpen = false ;
@@ -121,12 +121,11 @@ public void Enqueue(object o) {
121
121
///<remarks>
122
122
///Callers of Dequeue() will block if no items are available
123
123
///until some other thread calls Enqueue() or the queue is
124
- ///closed. If the queue is closed (by a call to Close()), this
125
- ///method will throw EndOfStreamException.
124
+ ///closed. In the latter case this method will throw
125
+ ///EndOfStreamException.
126
126
///</remarks>
127
127
public object Dequeue ( ) {
128
128
lock ( m_queue ) {
129
- EnsureIsOpen ( ) ;
130
129
while ( m_queue . Count == 0 ) {
131
130
EnsureIsOpen ( ) ;
132
131
Monitor . Wait ( m_queue ) ;
@@ -151,15 +150,15 @@ public object Dequeue() {
151
150
/// whereas Dequeue() will.
152
151
///</para>
153
152
///<para>
154
- /// If, at the time of call, the queue is in a closed state
155
- /// (by a call to Close()), this method will throw
156
- /// EndOfStreamException.
153
+ /// If at the time of call the queue is empty and in a
154
+ /// closed state (following a call to Close()), then this
155
+ /// method will throw EndOfStreamException.
157
156
///</para>
158
157
///</remarks>
159
158
public object DequeueNoWait ( object defaultValue ) {
160
159
lock ( m_queue ) {
161
- EnsureIsOpen ( ) ;
162
160
if ( m_queue . Count == 0 ) {
161
+ EnsureIsOpen ( ) ;
163
162
return defaultValue ;
164
163
} else {
165
164
return m_queue . Dequeue ( ) ;
@@ -197,7 +196,8 @@ public object DequeueNoWait(object defaultValue) {
197
196
/// System.Threading.Monitor.Wait(object,int).
198
197
///</para>
199
198
///<para>
200
- /// If, at any time during the call, the queue is in or
199
+ /// If no items are present and the queue is in a closed
200
+ /// state, or if at any time while waiting the queue is
201
201
/// transitions to a closed state (by a call to Close()), this
202
202
/// method will throw EndOfStreamException.
203
203
///</para>
@@ -210,8 +210,8 @@ public bool Dequeue(int millisecondsTimeout, out object result) {
210
210
211
211
DateTime startTime = DateTime . Now ;
212
212
lock ( m_queue ) {
213
- EnsureIsOpen ( ) ;
214
213
while ( m_queue . Count == 0 ) {
214
+ EnsureIsOpen ( ) ;
215
215
int elapsedTime = ( int ) ( ( DateTime . Now - startTime ) . TotalMilliseconds ) ;
216
216
int remainingTime = millisecondsTimeout - elapsedTime ;
217
217
if ( remainingTime <= 0 ) {
@@ -220,7 +220,6 @@ public bool Dequeue(int millisecondsTimeout, out object result) {
220
220
}
221
221
222
222
Monitor . Wait ( m_queue , remainingTime ) ;
223
- EnsureIsOpen ( ) ;
224
223
}
225
224
226
225
result = m_queue . Dequeue ( ) ;
0 commit comments