fix for: https://issues.apache.org/jira/browse/AMQNET-309
Project: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/commit/ce876d05 Tree: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/tree/ce876d05 Diff: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/diff/ce876d05 Branch: refs/heads/1.5.x Commit: ce876d0555c636b93914f39af8c6a40f57c40b6a Parents: 196ee4b Author: Timothy A. Bish <tab...@apache.org> Authored: Fri Jan 21 22:43:48 2011 +0000 Committer: Timothy A. Bish <tab...@apache.org> Committed: Fri Jan 21 22:43:48 2011 +0000 ---------------------------------------------------------------------- src/main/csharp/Util/MessageDispatchChannel.cs | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/blob/ce876d05/src/main/csharp/Util/MessageDispatchChannel.cs ---------------------------------------------------------------------- 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 @@ namespace Apache.NMS.Stomp.Util 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 @@ namespace Apache.NMS.Stomp.Util if(!Closed) { this.running = true; - this.waiter.Set(); - this.waiter.Reset(); + this.wakeAll.Reset(); } } } @@ -117,8 +123,7 @@ namespace Apache.NMS.Stomp.Util lock(mutex) { this.running = false; - this.waiter.Set(); - this.waiter.Reset(); + this.wakeAll.Set(); } } @@ -132,7 +137,7 @@ namespace Apache.NMS.Stomp.Util this.closed = true; } - this.waiter.Set(); + this.wakeAll.Set(); } } @@ -142,7 +147,6 @@ namespace Apache.NMS.Stomp.Util { this.channel.AddLast(dispatch); this.waiter.Set(); - this.waiter.Reset(); } } @@ -152,7 +156,6 @@ namespace Apache.NMS.Stomp.Util { this.channel.AddFirst(dispatch); this.waiter.Set(); - this.waiter.Reset(); } } @@ -166,7 +169,8 @@ namespace Apache.NMS.Stomp.Util 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(); }