示例#1
0
        /// <summary>
        /// Removes a global event handler.
        /// You need to have registered the event before being able to remove it.
        /// </summary>
        /// <param name="e">The event type from which to deregister</param>
        /// <param name="del">The event handler to deregister for this event type</param>
        /// <exception cref="ArgumentNullException">If one of the parameters is null</exception>
        public static void RemoveHandler(DOLEvent e, DOLEventHandler del)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e", "No event type given!");
            }

            if (del == null)
            {
                throw new ArgumentNullException("del", "No event handler given!");
            }

            m_globalHandlerCollection.RemoveHandler(e, del);
        }
示例#2
0
        /// <summary>
        /// Removes a single event handler from an object.
        /// You need to have registered the event before being
        /// able to remove it.
        /// </summary>
        /// <param name="obj">The object that needs to be the sender of events</param>
        /// <param name="e">The event type from which to deregister</param>
        /// <param name="del">The event handler to deregister for this event type</param>
        /// <exception cref="ArgumentNullException">If one of the parameters is null</exception>
        public static void RemoveHandler(object obj, DOLEvent e, DOLEventHandler del)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj", "No object given!");
            }

            if (e == null)
            {
                throw new ArgumentNullException("e", "No event type given!");
            }

            if (del == null)
            {
                throw new ArgumentNullException("del", "No event handler given!");
            }

            DOLEventHandlerCollection col = null;

            if (Lock.TryEnterReadLock(LOCK_TIMEOUT))
            {
                try
                {
                    m_gameObjectEventCollections.TryGetValue(obj, out col);
                }
                finally
                {
                    Lock.ExitReadLock();
                }
            }
            else
            {
                log.ErrorFormat("Timeout exceeded on attempt to RemoveHandler for object: {0}, event: {1}", obj.ToString(), e.Name);
            }

            if (col != null)
            {
                col.RemoveHandler(e, del);
            }
        }