Пример #1
0
        public void HandleWeakEvent()
        {
            Dummy dummy = new Dummy();
            bool weakEventReceived = false;
            var listener = new WeakEventListener<PropertyChangedEventArgs>((sender, eventArgs) => weakEventReceived = true);

            PropertyChangedEventManager.AddListener(dummy, listener, String.Empty);
            dummy.RaisePropertyChanged();
            Assert.IsTrue(weakEventReceived);
            weakEventReceived = false;
        }
Пример #2
0
        public void AllowsGarbageCollection()
        {
            Dummy dummy = new Dummy();
            bool weakEventReceived = false;
            var listener = new WeakEventListener<PropertyChangedEventArgs>((sender, eventArgs) => weakEventReceived = true);

            PropertyChangedEventManager.AddListener(dummy, listener, String.Empty);

            WeakReference weakReference = new WeakReference(listener);
            listener = null;
            GC.Collect();

            Assert.IsFalse(weakReference.IsAlive);
            Assert.IsFalse(weakEventReceived);
        }