title: How to make a thread wait until a variable reaches one of a set of values in .NET/Csharp
body: <p>I've written a class that has a property of type <code>TProperty</code> and an event of type <code>Action&lt;TProperty&gt;</code> that fires whenever that property changes.  <code>TProperty</code> is typically an enum type, but that shouldn't matter.</p>
  
  <p>I'd like to create a method with signature </p>
  
  <pre><code>bool WaitUntilPropertyIs(int TimeoutMs, IEnumerable&lt;TProperty&gt; AllowedValues) 
  </code></pre>
  
  <p>that blocks the thread that called it until the property changes to a value that is in <code>AllowedValues</code>.  Ofcourse if WaitUntilPropertyIs is called when the property is alread one of the <code>AllowedValues</code>, there should be no blocking.  <code>WaitUntilPropertyIs</code> should wait at most <code>TimeoutMs</code> and return false if the Timeout is exceeded (normal <code>AutoResetEvent.Wait</code> semantics).</p>
  
  <p>I'm open to using Reactive Extensions or traditional synchronization constructs.</p>