protected override void OnStart(string[] args) { AttendanceLoader loader = new AttendanceLoader(); timer = new Timer(stateInfo => { AttendanceLoader al = (AttendanceLoader)stateInfo; al.LoadNewAttendanceInfo(); DateTime now = DateTime.Now; DateTime tomorrow = DateTime.Parse(now.ToString("yyyy-MM-dd 06:00:00")).AddDays(1); timer.Change(tomorrow - now, TimeSpan.Zero); }, loader, TimeSpan.Zero, TimeSpan.Zero); }
protected override void RunAsConsole() { Console.WriteLine("尝试读取最新的考勤信息..."); try { AttendanceLoader loader = new AttendanceLoader(); loader.LoadNewAttendanceInfo(); } catch (Exception e) { Console.WriteLine("发生错误"); Console.WriteLine(e.ToString()); } Console.WriteLine("读取完成,按任意键退出"); Console.ReadKey(); }