/// <summary> /// 执行任务(更新缓存) /// </summary> /// <param name="state"></param> protected override void Execute(object state) { try { string message = null; CacheLevel level = default(CacheLevel); if (state.GetType().IsEnum&& state is CacheLevel) { level = (CacheLevel)state; string levelName = null; switch (level) { case CacheLevel.Hight: levelName = "高级别"; break; case CacheLevel.Lower: levelName = "低级别"; break; case CacheLevel.Middel: levelName = "中等级别"; break; case CacheLevel.Permanent: levelName = "持久级别"; break; } //获取本次需要更新的缓存 var list = CacheCollection.GetCacheList(level); lock (Startup.uploadCacheObjectLock) { //更新当前级别的缓存 CacheCollection.Update(level); } if (null != list && list.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (var item in list) { sb.AppendLine(string.Format("{0}缓存“{1}”已更新!", levelName, EnumExtensions.GetDescription <CacheItemType>(item.ItemType))); } message = sb.ToString(); } else { message = string.Format("{0}缓存没有需要更新的缓存项", levelName); } } if (string.IsNullOrWhiteSpace(message)) { message = "没有任何可更新的缓存项"; } RunLogger(message); } catch (Exception ex) { this.OnThrowException(ex); } }