Ejemplo n.º 1
0
 /// <summary>
 /// Adds an event handler to the list, if it's already added do nothing
 /// </summary>
 /// <param name="e">The event from which we add a handler</param>
 /// <param name="del">The callback method</param>
 public void AddHandlerUnique(RoadEvent e, RoadEventHandler del)
 {
     try
     {
         m_lock.AcquireWriterLock(TIMEOUT);
         try
         {
             WeakMulticastDelegate deleg = (WeakMulticastDelegate)m_events[e];
             if (deleg == null)
             {
                 m_events[e] = new WeakMulticastDelegate(del);
             }
             else
             {
                 m_events[e] = WeakMulticastDelegate.CombineUnique(deleg, del);
             }
         }
         finally
         {
             m_lock.ReleaseWriterLock();
         }
     }
     catch (ApplicationException ex)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Failed to add event handler!", ex);
         }
     }
 }
Ejemplo n.º 2
0
 public void AddHandlerUnique(RoadEvent e, RoadEventHandler del)
 {
     try
     {
         this.m_lock.AcquireWriterLock(3000);
         try
         {
             WeakMulticastDelegate deleg = (WeakMulticastDelegate)this.m_events[e];
             if (deleg == null)
             {
                 this.m_events[e] = new WeakMulticastDelegate(del);
             }
             else
             {
                 this.m_events[e] = WeakMulticastDelegate.CombineUnique(deleg, del);
             }
         }
         finally
         {
             this.m_lock.ReleaseWriterLock();
         }
     }
     catch (ApplicationException ex)
     {
         LogProvider.Default.Error("Failed to add event handler!", ex);
     }
 }
Ejemplo n.º 3
0
 public void AddHandlerUnique(RoadEvent e, RoadEventHandler del)
 {
     try
     {
         this.m_lock.AcquireWriterLock(3000);
         try
         {
             WeakMulticastDelegate weakMulticastDelegate = (WeakMulticastDelegate)this.m_events[e];
             if (weakMulticastDelegate == null)
             {
                 this.m_events[e] = new WeakMulticastDelegate(del);
             }
             else
             {
                 this.m_events[e] = WeakMulticastDelegate.CombineUnique(weakMulticastDelegate, del);
             }
         }
         finally
         {
             this.m_lock.ReleaseWriterLock();
         }
     }
     catch (ApplicationException exception)
     {
         if (RoadEventHandlerCollection.log.IsErrorEnabled)
         {
             RoadEventHandlerCollection.log.Error("Failed to add event handler!", exception);
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds an event handler to the list, if it's already added do nothing
        /// </summary>
        /// <param name="e">The event from which we add a handler</param>
        /// <param name="del">The callback method</param>
        public void AddHandlerUnique(DOLEvent e, DOLEventHandler del)
        {
            if (_lock.TryEnterWriteLock(LOCK_TIMEOUT))
            {
                try
                {
                    WeakMulticastDelegate deleg;

                    if (!_events.TryGetValue(e, out deleg))
                    {
                        _events.Add(e, new WeakMulticastDelegate(del));
                    }
                    else
                    {
                        _events[e] = WeakMulticastDelegate.CombineUnique(deleg, del);
                    }
                }
                finally
                {
                    _lock.ExitWriteLock();
                }
            }
        }