[Modify] Polish it

This commit is contained in:
sta 2016-07-25 16:23:30 +09:00
parent 6786cb017b
commit a870f7389f

View File

@ -11,16 +11,16 @@ namespace Example
internal class Notifier : IDisposable
{
private volatile bool _enabled;
private ManualResetEvent _exited;
private Queue<NotificationMessage> _queue;
private object _sync;
private ManualResetEvent _waitHandle;
public Notifier ()
{
_enabled = true;
_exited = new ManualResetEvent (false);
_queue = new Queue<NotificationMessage> ();
_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,16 +61,17 @@ 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 ()
{