You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "David Holroyd (JIRA)" <ji...@apache.org> on 2007/09/23 15:09:24 UTC

[jira] Created: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
-------------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: AMQNET-64
                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
             Project: ActiveMQ .Net
          Issue Type: Bug
          Components: ActiveMQ Client
         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
            Reporter: David Holroyd
            Assignee: James Strachan


I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:

{noformat}
Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
Parameter name: millisecondsTimeout
   at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
   at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
   at ActiveMQ.Dispatcher.Dequeue()
   at ActiveMQ.MessageConsumer.Receive()
   at Test.Bridge.Main(String[] args)
{noformat}

The code in question is,

{code:title=Bridge.cs}
namespace Test {

	using System;
	using NMS;
	using ActiveMQ;

	public class Bridge {

		public static void Main(string[] args) {

			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
			using (IConnection connection = factory.CreateConnection())
			{
			    Console.WriteLine("Created a connection!");
			    
			    ISession session = connection.CreateSession();
			    
			    IDestination destination = session.GetQueue("FOO.BAR");
			    Console.WriteLine("Using destination: " + destination);
			    
			    // lets create a consumer and producer
			    IMessageConsumer consumer = session.CreateConsumer(destination);
			    
			    IMessageProducer producer = session.CreateProducer(destination);
			    producer.Persistent = true;
			    
			    // lets send a message
			    ITextMessage request = session.CreateTextMessage("Hello World!");
			    request.NMSCorrelationID = "abc";
			    request.Properties["NMSXGroupID"] = "cheese";
			    request.Properties["myHeader"] = "James";
			    
			    producer.Send(request);
			    
			    // lets consume a message
			    ITextMessage message = (ITextMessage) consumer.Receive();
			    if (message == null)
			    {
				Console.WriteLine("No message received!");
			    }
			    else
			    {
				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
				Console.WriteLine("Received message with text: " + message.Text);
			    }
			}

		}
	}
}
{code}


The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).


I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Commented: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by semog <e....@gmail.com>.
David,

Glad I could help!  I integrated your final changes (with the
Timeout.Inifinite constant) into my codebase as well.  Hopefully, they'll be
committed to the main code line in a short bit.  Thanks for contributing
your fixes.

- Jim


JIRA jira@apache.org wrote:
> 
> 
>     [
> https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40175
> ] 
> 
> David Holroyd commented on AMQNET-64:
> -------------------------------------
> 
> Jim!  Bless you!  I was hunting for the bug caused by that semicolon for
> over an hour on Sunday.
> 
> So, I've tried running with the attached patch, and my testing shows this
> codepath now seems to be working (it has both the fixes you suggested).
> 
>> occasional exception in ActiveMQ.Dispatcher.Dequeue() :
>> millisecondsTimeout must be either non-negative and less than or equal to
>> Int32.MaxValue or -1.
>> 
> 

-- 
View this message in context: http://www.nabble.com/-jira--Created%3A-%28AMQNET-64%29-occasional-exception-in-ActiveMQ.Dispatcher.Dequeue%28%29-%3A-millisecondsTimeout-must-be-either-non-negative-and-less-than-or-equal-to-Int32.MaxValue-or--1.-tf4504370s2354.html#a12868304
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


[jira] Issue Comment Edited: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "David Holroyd (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40167 ] 

dholroyd edited comment on AMQNET-64 at 9/23/07 8:33 AM:
--------------------------------------------------------------

So a cast from double to int appears to be the immediate problem.  Here's a naive workaround,

{noformat}
--- src/main/csharp/ActiveMQ/Dispatcher.cs      (revision 578465)
+++ src/main/csharp/ActiveMQ/Dispatcher.cs      (working copy)
@@ -127,8 +127,17 @@
 
             while (!bClosed && rc == null)
             {
-                if( !messageReceivedEventHandle.WaitOne((int)timeout.TotalMilliseconds, false) )
+                int wait;
+                if (timeout.TotalMilliseconds > Int32.MaxValue)
                 {
+                                       wait = Int32.MaxValue;
+                }
+                               else
+                               {
+                                       wait = (int)timeout.TotalMilliseconds;
+                               }
+                if( !messageReceivedEventHandle.WaitOne(wait, false));
+                {
                     break;
                 }
                                lock (semaphore)
{noformat}

But when this codepath is hit, the test application doesn't receive any message ({{consumer.Receive()}} returns {{null}}).


(Feels as if the no-args version of Dequeue() would do better to pass a {{null}} timeout to indicate 'wait forever', too.)

      was (Author: dholroyd):
    So a cast from double to int appears to be the immediate problem.  Here's a naive workaround,

{noformat}
--- src/main/csharp/ActiveMQ/Dispatcher.cs      (revision 578465)
+++ src/main/csharp/ActiveMQ/Dispatcher.cs      (working copy)
@@ -127,8 +127,17 @@
 
             while (!bClosed && rc == null)
             {
-                if( !messageReceivedEventHandle.WaitOne((int)timeout.TotalMilliseconds, false) )
+                int wait;
+                if (timeout.TotalMilliseconds > Int32.MaxValue)
                 {
+                                       wait = Int32.MaxValue;
+                }
+                               else
+                               {
+                                       wait = (int)timeout.TotalMilliseconds;
+                               }
+                if( !messageReceivedEventHandle.WaitOne(wait, false));
+                {
                     break;
                 }
                                lock (semaphore)
{noformat}

But when this codepath is hit, the test application doesn't recieve an error message.


(Feels as if the no-args version of Dequeue() would do better to pass a {{null}} timeout to indicate 'wait forever', too.)
  
> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "Jim Gomes (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jim Gomes resolved AMQNET-64.
-----------------------------

    Resolution: Fixed

> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>         Attachments: ConsumerTest.cs, Dispatcher_timeout_cast-patch.diff
>
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "Kristofor Jacobson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kristofor Jacobson updated AMQNET-64:
-------------------------------------

    Attachment: ConsumerTest.cs

This copy of ConsumerTest reproduces the issue.

After implementing a fix that was basically the same as the one already posted in the forum, the test passed.

> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>         Attachments: ConsumerTest.cs, Dispatcher_timeout_cast-patch.diff
>
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "David Holroyd (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40175 ] 

David Holroyd commented on AMQNET-64:
-------------------------------------

Jim!  Bless you!  I was hunting for the bug caused by that semicolon for over an hour on Sunday.

So, I've tried running with the attached patch, and my testing shows this codepath now seems to be working (it has both the fixes you suggested).

> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "Jim Gomes (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40174 ] 

Jim Gomes commented on AMQNET-64:
---------------------------------

David,
Thanks for adding this issue.  Overall, I think these changes improve this area of the code.  However, a couple of comments on the second set of changes.  

The first is that you added a semi-colon to the end of the if-statement on line 130.  This introduced a bug in the code.  You'll want to remove that from your changes.

The second is with the constructor for the TimeSpan object in the Dequeue() function.  I see what you are attempting to do as stated in the AutoResetEvent.WaitOne() method documentation.  If the TimeSpan object represents -1 milliseconds, it will wait indefinitely.  However, the TimeSpan object that is being created is not -1 milliseconds.  It looks to be a TimeSpan of  -1 100-nanoseconds (or ticks), which may not be the same. This may cause a problem.  I would suggest changing to the following code:

{code}
public IMessage Dequeue()
{
    // Create a TimeSpan of -1 milliseconds, which will wait indefinitely.
    return Dequeue(TimeSpan.FromMilliseconds(-1));
}
{code}


> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "Kristofor Jacobson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40514 ] 

kjacobson edited comment on AMQNET-64 at 10/26/07 12:48 PM:
---------------------------------------------------------------------

This new test (found in the attached ConsumerTest.cs) reproduces the issue.

{code}
using System.Threading;
{code}

{code}
        [Test]
        public void TestNoTimeoutConsumer()
        {
            destinationType = DestinationType.Queue;
            // Launch a thread to perform IMessageConsumer.Receive().
            // If it doesn't fail in less than three seconds, no exception was thrown.
            Thread receiveThread = new Thread(doTestNoTimeoutConsumer);
            receiveThread.Start(Session.CreateConsumer((IQueue) Destination));
            if (receiveThread.Join(3000)) {
                Assert.Fail("IMessageConsumer.Receive() returned without blocking.  Test failed.");
            } else {
                // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
                receiveThread.Interrupt();
            }
        }

        public void doTestNoTimeoutConsumer(Object parameter)
        {
            IMessageConsumer consumer = (IMessageConsumer ) parameter;
            try
            {
                consumer.Receive();
            } catch (ArgumentOutOfRangeException e) {
                // The test failed.  We will know because the timeout will expire inside TestNoTimeoutConsumer().
                Console.WriteLine("Test failed with exception: " + e.Message);
            } catch (ThreadInterruptedException e) {
                // The test succeeded!  We were still blocked when we were interrupted.
            } catch (Exception e) {
                // Some other exception occurred.
                Console.WriteLine("Test failed with exception: " + e.Message);
            }
        }
{code}

After implementing a fix to Dispatcher.cs that was basically the same as the one already posted in the forum, the test passed.

      was (Author: kjacobson):
    This copy of ConsumerTest reproduces the issue.

After implementing a fix that was basically the same as the one already posted in the forum, the test passed.
  
> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>         Attachments: ConsumerTest.cs, Dispatcher_timeout_cast-patch.diff
>
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "David Holroyd (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40167 ] 

David Holroyd commented on AMQNET-64:
-------------------------------------

So a cast from double to int appears to be the immediate problem.  Here's a naive workaround,

{noformat}
--- src/main/csharp/ActiveMQ/Dispatcher.cs      (revision 578465)
+++ src/main/csharp/ActiveMQ/Dispatcher.cs      (working copy)
@@ -127,8 +127,17 @@
 
             while (!bClosed && rc == null)
             {
-                if( !messageReceivedEventHandle.WaitOne((int)timeout.TotalMilliseconds, false) )
+                int wait;
+                if (timeout.TotalMilliseconds > Int32.MaxValue)
                 {
+                                       wait = Int32.MaxValue;
+                }
+                               else
+                               {
+                                       wait = (int)timeout.TotalMilliseconds;
+                               }
+                if( !messageReceivedEventHandle.WaitOne(wait, false));
+                {
                     break;
                 }
                                lock (semaphore)
{noformat}

But when this codepath is hit, the test application doesn't recieve an error message.


(Feels as if the no-args version of Dequeue() would do better to pass a {{null}} timeout to indicate 'wait forever', too.)

> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "David Holroyd (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

David Holroyd updated AMQNET-64:
--------------------------------

    Attachment: Dispatcher_timeout_cast-patch.diff

fix for cast from double MaxVal to int producing invalid negative timeout.

> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>         Attachments: Dispatcher_timeout_cast-patch.diff
>
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "David Holroyd (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40168 ] 

dholroyd edited comment on AMQNET-64 at 9/23/07 12:23 PM:
---------------------------------------------------------------

The following is probably superior to my previous attempt,

{noformat}
--- src/main/csharp/ActiveMQ/Dispatcher.cs      (revision 578465)
+++ src/main/csharp/ActiveMQ/Dispatcher.cs      (working copy)
@@ -127,7 +129,7 @@
 
             while (!bClosed && rc == null)
             {
-                if( !messageReceivedEventHandle.WaitOne((int)timeout.TotalMilliseconds, false) )
+                if( !messageReceivedEventHandle.WaitOne(timeout, false));
                 {
                     break;
                 }
@@ -145,7 +147,7 @@
         /// </summary>
         public IMessage Dequeue()
         {
-                       return Dequeue(TimeSpan.MaxValue);
+                       return Dequeue(new TimeSpan(-1));
         }
 
                internal void Close()
{noformat}

(as WaitOne() can take a TimeSpan argument directly.)

I'm still trying to work out why the WaitOne() call just seems to return {{false}} more-or-less immediately..

      was (Author: dholroyd):
    The following is probably superior to my previous attempt,

{noformat}
--- src/main/csharp/ActiveMQ/Dispatcher.cs      (revision 578465)
+++ src/main/csharp/ActiveMQ/Dispatcher.cs      (working copy)
@@ -89,11 +89,13 @@
         /// </summary>
         public void Enqueue(ActiveMQMessage message)
         {
+Console.WriteLine("Enqueue() called");
             lock (semaphore)
             {
                 queue.Enqueue(message);
                 messageReceivedEventHandle.Set();
             }
+Console.WriteLine("Enqueue() done");
         }
         
         /// <summary>
@@ -127,7 +129,7 @@
 
             while (!bClosed && rc == null)
             {
-                if( !messageReceivedEventHandle.WaitOne((int)timeout.TotalMilliseconds, false) )
+                if( !messageReceivedEventHandle.WaitOne(timeout, false));
                 {
                     break;
                 }
@@ -145,7 +147,7 @@
         /// </summary>
         public IMessage Dequeue()
         {
-                       return Dequeue(TimeSpan.MaxValue);
+                       return Dequeue(new TimeSpan(-1));
         }
 
                internal void Close()
{noformat}

(as WaitOne() can take a TimeSpan argument directly.)

I'm still trying to work out why the WaitOne() call just seems to return {{false}} more-or-less immediately..
  
> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (AMQNET-64) occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.

Posted by "David Holroyd (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQNET-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40168 ] 

David Holroyd commented on AMQNET-64:
-------------------------------------

The following is probably superior to my previous attempt,

{noformat}
--- src/main/csharp/ActiveMQ/Dispatcher.cs      (revision 578465)
+++ src/main/csharp/ActiveMQ/Dispatcher.cs      (working copy)
@@ -89,11 +89,13 @@
         /// </summary>
         public void Enqueue(ActiveMQMessage message)
         {
+Console.WriteLine("Enqueue() called");
             lock (semaphore)
             {
                 queue.Enqueue(message);
                 messageReceivedEventHandle.Set();
             }
+Console.WriteLine("Enqueue() done");
         }
         
         /// <summary>
@@ -127,7 +129,7 @@
 
             while (!bClosed && rc == null)
             {
-                if( !messageReceivedEventHandle.WaitOne((int)timeout.TotalMilliseconds, false) )
+                if( !messageReceivedEventHandle.WaitOne(timeout, false));
                 {
                     break;
                 }
@@ -145,7 +147,7 @@
         /// </summary>
         public IMessage Dequeue()
         {
-                       return Dequeue(TimeSpan.MaxValue);
+                       return Dequeue(new TimeSpan(-1));
         }
 
                internal void Close()
{noformat}

(as WaitOne() can take a TimeSpan argument directly.)

I'm still trying to work out why the WaitOne() call just seems to return {{false}} more-or-less immediately..

> occasional exception in ActiveMQ.Dispatcher.Dequeue() : millisecondsTimeout must be either non-negative and less than or equal to Int32.MaxValue or -1.
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-64
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-64
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: .NET 2.0, Windows 2000 Server under VMware, https://svn.apache.org/repos/asf/activemq/activemq-dotnet/trunk @ 578465
>            Reporter: David Holroyd
>            Assignee: James Strachan
>
> I tried a lightly modified version of the example code from http://activemq.apache.org/nms/nms.html and find that every few invocations of the test program, I see the following exception, rather than the normal 'Received message' output:
> {noformat}
> Unhandled Exception: System.ArgumentOutOfRangeException: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
> Parameter name: millisecondsTimeout
>    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>    at ActiveMQ.Dispatcher.Dequeue(TimeSpan timeout)
>    at ActiveMQ.Dispatcher.Dequeue()
>    at ActiveMQ.MessageConsumer.Receive()
>    at Test.Bridge.Main(String[] args)
> {noformat}
> The code in question is,
> {code:title=Bridge.cs}
> namespace Test {
> 	using System;
> 	using NMS;
> 	using ActiveMQ;
> 	public class Bridge {
> 		public static void Main(string[] args) {
> 			IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://192.168.9.162:61616"));
> 			using (IConnection connection = factory.CreateConnection())
> 			{
> 			    Console.WriteLine("Created a connection!");
> 			    
> 			    ISession session = connection.CreateSession();
> 			    
> 			    IDestination destination = session.GetQueue("FOO.BAR");
> 			    Console.WriteLine("Using destination: " + destination);
> 			    
> 			    // lets create a consumer and producer
> 			    IMessageConsumer consumer = session.CreateConsumer(destination);
> 			    
> 			    IMessageProducer producer = session.CreateProducer(destination);
> 			    producer.Persistent = true;
> 			    
> 			    // lets send a message
> 			    ITextMessage request = session.CreateTextMessage("Hello World!");
> 			    request.NMSCorrelationID = "abc";
> 			    request.Properties["NMSXGroupID"] = "cheese";
> 			    request.Properties["myHeader"] = "James";
> 			    
> 			    producer.Send(request);
> 			    
> 			    // lets consume a message
> 			    ITextMessage message = (ITextMessage) consumer.Receive();
> 			    if (message == null)
> 			    {
> 				Console.WriteLine("No message received!");
> 			    }
> 			    else
> 			    {
> 				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
> 				Console.WriteLine("Received message with text: " + message.Text);
> 			    }
> 			}
> 		}
> 	}
> }
> {code}
> The C# code is talking to ActiveMQ 4.1.1 running on the Linux host (I'm using NMS within VMware).
> I'll try to nose around the code and work out what's happening, but this is the first time I've ever worked with C#.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.