WaitHandle and infinity

WaitHandle and infinity

am 28.09.2007 22:17:20 von Israel

So I want to use an AutoResetEvent (just say) and wait for infinity
but also leave the current synch context what is the "right" way to do
this? There used to be the definition of infinity which I believe was
just -1 that could be passed in to the timeout (in ms). I *think*
this will work judge by the error messages I've gotten back but it's
not documented.
I tried the following:

lock(this)
{
AutoResetEvent myEvent = new AutoResetEvent(false);
myEvent.WaitOne(new TimeSpan.MaxValue, true);
}

But that yields the error:
System.ArgumentOutOfRangeException: Number must be either non-negative
or -1.Parameter name: timeout

So instead I'll probably just use int.MaxValue but still it feels
wrong since I like to be explicit and tell it to wait for ever.