/// <summary> /// 获取单例对象 /// </summary> /// <returns></returns> public static TimeDataManager GetTimeDataManager() { if (uniqueTimeDataManager != null) { return(uniqueTimeDataManager); } lock (locker) { uniqueTimeDataManager = new TimeDataManager(); uniqueTimeDataManager.EnsureDbCreated(); // 只检查一次是否建库建表 uniqueTimeDataManager.LoadDataFromDb(); // 读入数据 int SaveToDbTimeSlice = ConfigService.GetConfigService().TSConfig.SaveToDbTimeSlice; // 定时写入数据库时间 System.Timers.Timer timer = new System.Timers.Timer { Interval = ConfigService.GetConfigService().TSConfig.SaveToDbTimeSlice, Enabled = true }; timer.Elapsed += TimeWriteToDb; timer.Start(); } return(uniqueTimeDataManager); }
/// <summary> /// 构造函数 /// </summary> public TimeStatisticService() { TDManager = TimeDataManager.GetTimeDataManager(); // 注入TimeDataManager }
/// <summary> /// 释放单例对象 /// </summary> public static void Dispose() { uniqueTimeDataManager = null; }
/// <summary> /// 构造方法 /// </summary> public ActivityMonitor() { configService = ConfigService.GetConfigService(); timeSlice = configService.TSConfig.TimeSlice; TDManager = TimeDataManager.GetTimeDataManager(); // 注入DataManager }