Exemplo n.º 1
0
        public void Invoke(object[] args)
        {
            WeakMulticastDelegate current = this;
            int start;

            while (current != null)
            {
                start = Environment.TickCount;

                if (current.weakRef == null)
                {
                    current.method.Invoke(null, args);
                }
                else if (current.weakRef.IsAlive)
                {
                    current.method.Invoke(current.weakRef.Target, args);
                }

                if ((Environment.TickCount - start) > 500)
                {
                    if (log.IsWarnEnabled)
                    {
                        log.Warn("WeakMulticastDelegate Invoke took " + (Environment.TickCount - start) + "ms.|" + current.ToString());
                    }
                }

                current = current.prev;
            }
        }
Exemplo n.º 2
0
 public static WeakMulticastDelegate Remove(WeakMulticastDelegate weakDelegate, Delegate realDelegate)
 {
     if (realDelegate == null || weakDelegate == null)
     {
         return(null);
     }
     return(weakDelegate.Remove(realDelegate));
 }
Exemplo n.º 3
0
        public WeakMulticastDelegate Combine(Delegate realDelegate)
        {
            WeakMulticastDelegate head = new WeakMulticastDelegate(realDelegate);

            head.prev = this.prev;

            this.prev = head;

            return this;
        }
Exemplo n.º 4
0
        public WeakMulticastDelegate Combine(Delegate realDelegate)
        {
            WeakMulticastDelegate head = new WeakMulticastDelegate(realDelegate);

            head.prev = this.prev;

            this.prev = head;

            return(this);
        }
Exemplo n.º 5
0
 public static WeakMulticastDelegate CombineUnique(WeakMulticastDelegate weakDelegate, Delegate realDelegate)
 {
     if (realDelegate == null)
     {
         return(null);
     }
     if (weakDelegate == null)
     {
         return(new WeakMulticastDelegate(realDelegate));
     }
     return(weakDelegate.CombineUnique(realDelegate));
 }
Exemplo n.º 6
0
        public WeakMulticastDelegate CombineUnique(Delegate realDelegate)
        {
            bool found = Equals(realDelegate);

            if (!found && prev != null)
            {
                WeakMulticastDelegate curNode = prev;
                while (!found && curNode != null)
                {
                    if (curNode.Equals(realDelegate))
                    {
                        found = true;
                    }
                    curNode = curNode.prev;
                }
            }

            return(found ? this : this.Combine(realDelegate));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Dumps the delegates in this multicast delegate to a string
        /// </summary>
        /// <returns>The string containing the formated dump</returns>
        public string Dump()
        {
            StringBuilder         builder = new StringBuilder();
            WeakMulticastDelegate current = this;
            int count = 0;

            while (current != null)
            {
                count++;
                if (current.weakRef == null)
                {
                    builder.Append("\t");
                    builder.Append(count);
                    builder.Append(") ");
                    builder.Append(current.method.Name);
                    builder.Append(System.Environment.NewLine);
                }
                else
                {
                    if (current.weakRef.IsAlive)
                    {
                        builder.Append("\t");
                        builder.Append(count);
                        builder.Append(") ");
                        builder.Append(current.weakRef.Target);
                        builder.Append(".");
                        builder.Append(current.method.Name);
                        builder.Append(Environment.NewLine);
                    }
                    else
                    {
                        builder.Append("\t");
                        builder.Append(count);
                        builder.Append(") INVALID.");
                        builder.Append(current.method.Name);
                        builder.Append(Environment.NewLine);
                    }
                }
                current = current.prev;
            }
            return(builder.ToString());
        }
Exemplo n.º 8
0
        public WeakMulticastDelegate Remove(Delegate realDelegate)
        {
            if (Equals(realDelegate))
            {
                return(this.prev);
            }

            WeakMulticastDelegate current = this.prev;
            WeakMulticastDelegate last    = this;

            while (current != null)
            {
                if (current.Equals(realDelegate))
                {
                    last.prev    = current.prev;
                    current.prev = null;
                    break;
                }
                last    = current;
                current = current.prev;
            }

            return(this);
        }
Exemplo n.º 9
0
 public static WeakMulticastDelegate Remove(WeakMulticastDelegate weakDelegate, Delegate realDelegate)
 {
     if (realDelegate == null || weakDelegate == null) return null;
     return weakDelegate.Remove(realDelegate);
 }
Exemplo n.º 10
0
 public static WeakMulticastDelegate CombineUnique(WeakMulticastDelegate weakDelegate, Delegate realDelegate)
 {
     if (realDelegate == null) return null;
     if (weakDelegate == null) return new WeakMulticastDelegate(realDelegate);
     return weakDelegate.CombineUnique(realDelegate);
 }
Exemplo n.º 11
0
 public static WeakMulticastDelegate operator -(WeakMulticastDelegate d, Delegate realD)
 {
     return(WeakMulticastDelegate.Remove(d, realD));
 }
Exemplo n.º 12
0
 public static WeakMulticastDelegate operator +(WeakMulticastDelegate d, Delegate realD)
 {
     return(WeakMulticastDelegate.Combine(d, realD));
 }