Exemplo n.º 1
0
        protected virtual void OnNewBikeArrivedEvent(NewBikeEventArgs args)
        {
            /**
             * There is a race condition we could encounter here where
             * after we've done the null check (because event programing is multithreaded)
             * the last subscriber unsubscribes. So we make a copy of the event to avoid that
             */
            EventHandler <NewBikeEventArgs> handler = NewBikeArrivedEvent;

            // If there are no subscribers this will be null
            // so there's no point in publishing it.
            if (handler != null)
            {
                handler(this, args);
            }
        }
Exemplo n.º 2
0
 private void HandleNewBikeEvents(object sender, NewBikeEventArgs args)
 {
     Console.WriteLine($" - {_name} just found out that {_shop.Name} now sells the {args.NameOfBike} bike");
 }