コード例 #1
0
 public void Invoke(object[] args)
 {
     for (WeakMulticastDelegate weakMulticastDelegate = this; weakMulticastDelegate != null; weakMulticastDelegate = weakMulticastDelegate.prev)
     {
         int tickCount = Environment.TickCount;
         if (weakMulticastDelegate.weakRef == null)
         {
             weakMulticastDelegate.method.Invoke(null, args);
         }
         else
         {
             if (weakMulticastDelegate.weakRef.IsAlive)
             {
                 weakMulticastDelegate.method.Invoke(weakMulticastDelegate.weakRef.Target, args);
             }
         }
         if (Environment.TickCount - tickCount > 500 && WeakMulticastDelegate.log.IsWarnEnabled)
         {
             WeakMulticastDelegate.log.Warn(string.Concat(new object[]
             {
                 "Invoke took ",
                 Environment.TickCount - tickCount,
                 "ms! ",
                 weakMulticastDelegate.ToString()
             }));
         }
     }
 }
コード例 #2
0
 public void InvokeSafe(object[] args)
 {
     for (WeakMulticastDelegate current = this; current != null; current = current.prev)
     {
         int start = Environment.TickCount;
         try
         {
             if (current.weakRef == null)
             {
                 current.method.Invoke(null, args);
             }
             else
             {
                 if (current.weakRef.IsAlive)
                 {
                     current.method.Invoke(current.weakRef.Target, args);
                 }
             }
         }
         catch (Exception ex)
         {
             LogProvider.Default.Error("InvokeSafe", ex);
         }
         if (Environment.TickCount - start > 500)
         {
             LogProvider.Default.Warn(string.Concat(new object[]
             {
                 "InvokeSafe took ",
                 Environment.TickCount - start,
                 "ms! ",
                 current.ToString()
             }));
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Invokes the delegate with the given arguments
        /// If one target throws an exception the other targets
        /// won't be affected.
        /// </summary>
        /// <param name="args">the argument array to pass to the target</param>
        public void InvokeSafe(object[] args)
        {
            WeakMulticastDelegate current = this;

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

                try
                {
                    if (current.weakRef == null)
                    {
                        current.method.Invoke(null, args);
                    }
                    else if (current.weakRef.IsAlive)
                    {
                        current.method.Invoke(current.weakRef.Target, args);
                    }
                }
                catch (Exception ex)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("InvokeSafe", ex);
                    }
                }

                if (Environment.TickCount - start > 500)
                {
                    if (log.IsWarnEnabled)
                    {
                        log.Warn("InvokeSafe took " + (Environment.TickCount - start) + "ms! " + current.ToString());
                    }
                }
                current = current.prev;
            }
        }