ch8_08.cs

来自「《c#技术内幕代码》」· CS 代码 · 共 48 行

CS
48
字号
using System;
using System.Timers;
using System.Diagnostics;

public class CH8_8
{
    public static int Counter;
    
    public static void Main(string[] args)
    {
         // Create the schedule and add the handler.
         Schedule s = new Schedule();
         s.EventOccurred+=new OccurredEventHandler(HandleEvent);

	 // Run the pattern every day
         DailyPattern days = new DailyPattern(1);
	 
         // Start at 8:00 a.m.
         days.StartTime = new TimeSpan(8,0,0);
	 
         // End at noon
         days.EndTime = new TimeSpan(12,0,0);
	 
         // Do it once every half-minute
         days.Interval = new TimeSpan(0,0,30);

         // Add the pattern to the scheduler
         s.RecurrencePatterns.Add(days);
	 
         // Initialize counter
	 Counter = 0;

         // Enable it
         s.Enabled = true;

         // Wait for user to quit program.
         Console.WriteLine("Press \'q\' to quit the sample");
         while(Console.Read()!='q');
    }

    // Define the event handler.
    public static void HandleEvent(object source, OccurredEventArgs e)
    {
       Counter ++;
       Console.WriteLine("Counter: {0}", Counter );
    
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?