Async programming and WaitHandle.WaitOne

  • Thread starter Thread starter Harvey Morse
  • Start date Start date
H

Harvey Morse

According to the .NET Framework documentation for
WaitHandle.WaitOne(TimeSpan timeout, bool):

When overridden in a derived class, blocks the current
thread until the current instance receives a signal, using
a TimeSpan to measure the time interval and specifying whether
to exit the synchronization domain before the wait.

public virtual bool WaitOne(
TimeSpan timeout,
bool exitContext
);

The exitContext parameter is described as follows:

true to exit the synchronization domain for
the context before the wait (if in a synchronized
context), and reacquire it; otherwise, false.

(See

http://msdn.microsoft.com/library/e...stemThreadingWaitHandleClassWaitOneTopic3.asp

or

http://tinyurl.com/3yxlo

)

My question is: what is the "synchronized domain" that
they're discussing here? And, more to the point, how might
this affect the following code:

//==========================================================================

using System;
using System.Threading;

class Foo {
private TimeSpan m_ts;

Foo(long ts){
m_ts = ts;
}

private delegate object MyFooFunctionDelegate();

private object MyFooFunction(){
//do some work here and return something
}

void DoFooStuff(){
MyFooFunctionDelegate dlgt = new MyFooFunctionDelegate(this.MyFooFunction);

IAsyncResult ar = dlgt.BeginInvoke(null, null);
ar.AsyncWaitHandle.WaitOne(ts, false); //or true? when does it make a difference?
//does it ever in such a situation as this?
object o;
if (ar.IsCompleted) {
o = dlgt.EndInvoke(ar);
}
}
}
//==========================================================================



Harvey Morse, a/k/a, "The Threading Moron"
 
Back
Top