示例#1
0
 /// <summary>
 /// Queue a notification on the notification thread for the current
 /// listeners.  When the thread unqueues the notification, <see cref="NotifyListener(IEventListener)"/>
 /// is called on each listener from the notification thread.
 /// </summary>
 public virtual void NotifyChanged()
 {
     lock (notifyLock)
     {
         if (listeners != null)
         {
             if (notifyThread == null)
             {
                 notifyThread = new NotifyThread(this);
                 notifyThread.SetDaemon(true);
                 notifyThread.Start();
             }
             notifyThread.Queue(listeners.ToArray());
         }
     }
 }
示例#2
0
        public virtual void TestBlocking()
        {
            IQueue4 queue = new BlockingQueue();

            string[] data = { "a", "b", "c", "d" };
            queue.Add(data[0]);
            Assert.AreSame(data[0], queue.Next());
            var notifyThread = new NotifyThread
                                   (queue, data[1]);

            notifyThread.Start();
            var start = Runtime.CurrentTimeMillis();

            Assert.AreSame(data[1], queue.Next());
            var end = Runtime.CurrentTimeMillis();

            Assert.IsGreater(500, end - start);
        }
示例#3
0
 /// <summary>
 /// Queue a notification on the notification thread for the current
 /// listeners.  When the thread unqueues the notification, <see cref="NotifyListener(IEventListener)"/>
 /// is called on each listener from the notification thread.
 /// </summary>
 public virtual void NotifyChanged()
 {
     lock (notifyLock)
     {
         if (listeners != null)
         {
             if (notifyThread == null)
             {
                 notifyThread = new NotifyThread(this)
                 {
                     IsBackground = true
                 };
                 notifyThread.Start();
             }
             notifyThread.Queue(listeners.ToArray());
         }
     }
 }
示例#4
0
 public virtual void TestBlocking()
 {
     IQueue4 queue = new BlockingQueue();
     string[] data = {"a", "b", "c", "d"};
     queue.Add(data[0]);
     Assert.AreSame(data[0], queue.Next());
     var notifyThread = new NotifyThread
         (queue, data[1]);
     notifyThread.Start();
     var start = Runtime.CurrentTimeMillis();
     Assert.AreSame(data[1], queue.Next());
     var end = Runtime.CurrentTimeMillis();
     Assert.IsGreater(500, end - start);
 }