fix for: https://issues.apache.org/jira/browse/AMQNET-309
diff --git a/src/main/csharp/Util/MessageDispatchChannel.cs b/src/main/csharp/Util/MessageDispatchChannel.cs
index 102b752..d2d33dc 100644
--- a/src/main/csharp/Util/MessageDispatchChannel.cs
+++ b/src/main/csharp/Util/MessageDispatchChannel.cs
@@ -25,11 +25,18 @@
public class MessageDispatchChannel
{
private readonly Mutex mutex = new Mutex();
- private readonly ManualResetEvent waiter = new ManualResetEvent(false);
+ private readonly ManualResetEvent wakeAll = new ManualResetEvent(false);
+ private readonly AutoResetEvent waiter = new AutoResetEvent(false);
+ private WaitHandle[] waiters;
private bool closed;
private bool running;
private readonly LinkedList<MessageDispatch> channel = new LinkedList<MessageDispatch>();
+ public MessageDispatchChannel()
+ {
+ this.waiters = new WaitHandle[] { this.waiter, this.wakeAll };
+ }
+
#region Properties
public object SyncRoot
@@ -106,8 +113,7 @@
if(!Closed)
{
this.running = true;
- this.waiter.Set();
- this.waiter.Reset();
+ this.wakeAll.Reset();
}
}
}
@@ -117,8 +123,7 @@
lock(mutex)
{
this.running = false;
- this.waiter.Set();
- this.waiter.Reset();
+ this.wakeAll.Set();
}
}
@@ -132,7 +137,7 @@
this.closed = true;
}
- this.waiter.Set();
+ this.wakeAll.Set();
}
}
@@ -142,7 +147,6 @@
{
this.channel.AddLast(dispatch);
this.waiter.Set();
- this.waiter.Reset();
}
}
@@ -152,7 +156,6 @@
{
this.channel.AddFirst(dispatch);
this.waiter.Set();
- this.waiter.Reset();
}
}
@@ -166,7 +169,8 @@
if( timeout != TimeSpan.Zero && !Closed && ( Empty || !Running ) )
{
this.mutex.ReleaseMutex();
- this.waiter.WaitOne((int)timeout.TotalMilliseconds, false);
+ this.waiter.Reset();
+ WaitHandle.WaitAny(this.waiters, (int)timeout.TotalMilliseconds, false);
this.mutex.WaitOne();
}