예제 #1
0
        static void EventsAndDelegates()
        {
            var video = new EventsAndDelegates.Video()
            {
                Title = "Video 1"
            };

            // Publisher
            var videoEncoder = new VideoEncoder();

            // Subscribers
            var mailService    = new MailService();
            var messageService = new MessageService();

            // Subscriptions
            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;

            videoEncoder.Encode(video);
        }
예제 #2
0
        public event EventHandler <VideoEventArgs> VideoEncoded; // if we want to information from a custom class = (object source, VideoEventArgs args)

        public void Encode(Video video)
        {
            Console.WriteLine("encoding video");
            Thread.Sleep(3000);
            OnVideoEncoded(video);                         //Once the video encoding is finished, this method will notify all the subscribers
        }                                                  // raising the event here