示例#1
0
        private static async Task runObserver()
        {
            var timer = new Timer();
            var clock = new ConsoleClock();

            timer.Notify += clock.Update;

            timer.Start();

            await Task.Delay(4000);

            timer.Notify -= clock.Update;

            await Task.Delay(2000);

            timer.Notify += clock.Update;
        }
示例#2
0
    static void Main()
    {
        // ADDED FEATURE: Clear the console window.
        Console.Clear();

        // Save the top and left coordinates.
        _top = Console.CursorTop;
        _left = Console.CursorLeft;

        // Create a Tester object.
        Tester t = new Tester();

        // Create a ConsoleClock object.
        ConsoleClock cc = new ConsoleClock();

        // Subscribe to the event in the ConsoleClock.
        cc.OnUpdateClock += new UpdateClockHandler (t.TesterUpdateClockHandler);

        // Start the timer.
        cc.RunTheClock();

        // Display this when the program is shutting down.
        Console.Write ("\nPress <ENTER> to end: ");
        Console.ReadLine();
    }