Exemple #1
0
        /// <summary>
        /// Runs a scenario where an object's event-handler is null.
        /// </summary>
        private static void ScenarioNoSubscriber()
        {
            if (Jordon.HasMethodAsEventHandler("OnWorkCompleted"))
            {
                // This will remove the method as an event handler.
                Jordon.WorkCompleted -= Loren.OnWorkCompleted;
            }

            // No event-handling will be invoked by this method.
            Task.WaitAll(Jordon.DoWork());
        }
Exemple #2
0
        /// <summary>
        /// Runs a scenario where an object's event-handler is assigned
        /// a method from another object.
        /// </summary>
        private static void ScenarioHasSubscriber()
        {
            /* Link the event to a method of the subscribing object.
             * When "WorkCompleted" is invoked, the event-handler on the
             * right side of the assignment will run.
             */
            Jordon.WorkCompleted += Loren.OnWorkCompleted;

            Task[] tasks =
            {
                // Run an independent method that will eventually invoke the event.
                Jordon.DoWork(),
                Loren.DoWork()
            };

            Task.WaitAll(tasks);
        }