/// <summary> /// /// </summary> /// <param name="type">1普通轮询执行 2 Quartz调度作业</param> public TaskManager(int type) { Task.Factory.StartNew(() => { T8ConfigItemDic = T8ConfigHelper.CloneT8ConfigItem(); if (T8ConfigItemDic == null) { T8ConfigItemDic = new ConcurrentDictionary <string, T8ConfigItemEntity>(); } }); if (type == 1) { //初始化任务队列 InitTaskQueue(); } else { T8ConfigItemDic = T8ConfigHelper.CloneT8ConfigItem(); if (T8ConfigItemDic == null) { T8ConfigItemDic = new ConcurrentDictionary <string, T8ConfigItemEntity>(); } } }
/// <summary> /// 检测T8ConfigItemDic是否为空 /// </summary> private void CheckT8CofigItem(CancellationToken ct) { int intervaltime = 1000 * 30; //任务项为空,间隔30秒重新检测 int intervaltime2 = 1000 * 1800; //任务项为空,休息30分钟重新检测 while (true) { ct.ThrowIfCancellationRequested(); if (T8ConfigItemDic == null || T8ConfigItemDic.Keys.Count == 0) { T8ConfigItemDic = T8ConfigHelper.CloneT8ConfigItem(); if (T8ConfigItemDic != null && T8ConfigItemDic.Keys.Count > 0) { for (int i = 0; i < intervaltime2; i++) { ct.ThrowIfCancellationRequested(); Thread.Sleep(1000); } } } else { for (int i = 0; i < intervaltime; i++) { ct.ThrowIfCancellationRequested(); Thread.Sleep(1000); } } } }