diff --git a/Example/Notifier.cs b/Example/Notifier.cs index f21eec32..5371c37a 100644 --- a/Example/Notifier.cs +++ b/Example/Notifier.cs @@ -11,16 +11,16 @@ namespace Example internal class Notifier : IDisposable { private volatile bool _enabled; + private ManualResetEvent _exited; private Queue _queue; private object _sync; - private ManualResetEvent _waitHandle; public Notifier () { _enabled = true; + _exited = new ManualResetEvent (false); _queue = new Queue (); _sync = ((ICollection) _queue).SyncRoot; - _waitHandle = new ManualResetEvent (false); ThreadPool.QueueUserWorkItem ( state => { @@ -40,8 +40,9 @@ namespace Example } } - _waitHandle.Set (); - }); + _exited.Set (); + } + ); } public int Count { @@ -60,15 +61,16 @@ namespace Example public void Close () { _enabled = false; - _waitHandle.WaitOne (); - _waitHandle.Close (); + _exited.WaitOne (); + _exited.Close (); } public void Notify (NotificationMessage message) { - lock (_sync) + lock (_sync) { if (_enabled) _queue.Enqueue (message); + } } void IDisposable.Dispose ()