📄 ch8_08.cs
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -