From a870f7389fcd7ade29a996101205f988db7f1551 Mon Sep 17 00:00:00 2001 From: sta Date: Mon, 25 Jul 2016 16:23:30 +0900 Subject: [PATCH] [Modify] Polish it --- Example/Notifier.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 ()