Details

    • Type: New Feature
    • Status: Open
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 0.6 RC3
    • Fix Version/s: FUTURES
    • Component/s: Spring-NET-CORE
    • Labels:
      None
    • Environment:
      event handling

      Description

      Utility class, an event handler that will not prevent object from GC just because we have added and event handler to them.

      public class WeakEventHandler
      {
      private WeakReference weakRefToTarget;
      private MethodInfo method;

      public WeakEventHandler(EventHandler originalDelegate)

      { weakRefToTarget = new WeakReference(originalDelegate.Target); method = originalDelegate.Method; }

      private void DoInvoke(object sender, EventArgs args)
      {
      if (weakRefToTarget.IsAlive)
      {
      object originalTarget = weakRefToTarget.Target;
      if (originalTarget != null)

      { EventHandler orig = (EventHandler) Delegate.CreateDelegate( typeof (EventHandler), originalTarget, method.Name); orig(sender, args); }

      }
      }

      public static implicit operator EventHandler(WeakEventHandler wd)

      { EventHandler del = new EventHandler(wd.DoInvoke); return del; }

      }

        Attachments

          Activity

            People

            • Assignee:
              mark.pollack Mark Pollack
              Reporter:
              federico Federico Spinazzi
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: