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



git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@374076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-02-01 14:39:04 +00:00
parent e62711760b
commit a4b970bebc
1 changed files with 15 additions and 10 deletions

View File

@ -12,6 +12,8 @@ namespace OpenWire.Client.Core {
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 @@ namespace OpenWire.Client.Core {
public object AsyncState {
get { return response; }
set { response = (Response) value; }
set { Response = (Response) value; }
}
public bool IsCompleted {
@ -32,18 +34,21 @@ namespace OpenWire.Client.Core {
}
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);
}
}
}
}