public bool Wait(int timeout) { var handles = this.Handles; ManualResetEventSlim handle = null; try { lock (this.SyncRoot) { if (this.CompareState() == true) { return(true); } handle = new ManualResetEventSlim(); handles.Add(handle); } return(handle.WaitQuietly(timeout)); } finally { handle.DisposeQuietly(); lock (this.SyncRoot) { handles.Remove(handle); } } }
public T Wait() { ManualResetEventSlim resetEvent = null; lock (this.ResetEventLock) { this.CheckExcepted(); if (this.Setted == true) { return(this.Response); } else { if (this.ResetEvent == null) { this.ResetEvent = new ManualResetEventSlim(); } resetEvent = this.ResetEvent; } } resetEvent.WaitQuietly(); this.CheckExcepted(); return(this.Response); }