Author: jstrachan
Date: Wed Feb 1 06:39:04 2006
New Revision: 374076
URL: http://svn.apache.org/viewcvs?rev=374076&view=rev
Log:
Thanks to the suggestion from Lars Eirik Sivesind of this article describing
how to convert Java concurrency programming constructs to .Net
http://www.ondotnet.com/pub/a/dotnet/2001/08/06/csharp.html?page=3
I've ported the FutureResponse class to use the proper .Net mechanism, Monitor
Modified:
incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/FutureResponse.cs
Modified:
incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/FutureResponse.cs
URL:
http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/FutureResponse.cs?rev=374076&r1=374075&r2=374076&view=diff
==============================================================================
---
incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/FutureResponse.cs
(original)
+++
incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/FutureResponse.cs
Wed Feb 1 06:39:04 2006
@@ -12,6 +12,8 @@
private Response response;
private Mutex asyncWaitHandle = new Mutex();
+ private Object semaphore = new Object();
+ private int maxWait = 3000;
private bool isCompleted;
public WaitHandle AsyncWaitHandle {
@@ -20,7 +22,7 @@
public object AsyncState {
get { return response; }
- set { response = (Response) value; }
+ set { Response = (Response) value; }
}
public bool IsCompleted {
@@ -32,18 +34,21 @@
}
public Response Response {
+ // Blocks the caller until a value has been set
get {
- // TODO use the proper .Net version of
notify/wait()
- while (response == null) {
- Thread.Sleep(100);
- }
- return response;
+ lock (semaphore) {
+ while (response == null) {
+ Monitor.Wait(semaphore,
maxWait);
+ }
+ return response;
+ }
}
set {
- asyncWaitHandle.WaitOne();
- response = value;
- isCompleted = true;
- asyncWaitHandle.ReleaseMutex();
+ lock (semaphore) {
+ response = value;
+ isCompleted = true;
+ Monitor.PulseAll(semaphore);
+ }
}
}
}