Пример #1
0
        /// <summary>
        /// Remove a handler for the given source's event.
        /// </summary>
        public static void RemoveHandler(CarSeller source,
                                         EventHandler <CarInfoEventArgs> handler)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            CurrentManager.ProtectedRemoveHandler(source, handler);
        }
Пример #2
0
        private static void Main(string[] args)
        {
            CarSeller cs  = new CarSeller();
            Customer  ct1 = new Customer(1);
            Customer  ct2 = new Customer(2);

            NewCarArrivedWeakEventManager.AddHandler(cs, ct1.GetNewCarInfo);
            NewCarArrivedWeakEventManager.AddHandler(cs, ct2.GetNewCarInfo);

            //ct1 = null;
            //ct2 = null;
            //GC.Collect();

            cs.GetNewCar("T-44", 5000);
        }
Пример #3
0
        /// <summary>
        /// Stop listening to the given source for the event.
        /// </summary>
        protected override void StopListening(object source)
        {
            CarSeller typedSource = (CarSeller)source;

            typedSource.NewCarArrived -= new EventHandler <CarInfoEventArgs>(OnNewCarArrived);
        }