using System; using System.Collections.Generic; using System.Linq; using MySystem.SpModels; using Library; using LitJson; using System.Threading; namespace MySystem { public class SycnSpActiveService { public readonly static SycnSpActiveService Instance = new SycnSpActiveService(); private SycnSpActiveService() { } public void Start() { Thread th = new Thread(StartDo); th.IsBackground = true; th.Start(); } public void StartDo() { while (true) { try { WebCMSEntities spdb = new WebCMSEntities(); PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities(); MpMainModels2.WebCMSEntities mpdb = new MpMainModels2.WebCMSEntities(); string Month = DateTime.Now.ToString("yyyyMM"); string Date = DateTime.Now.ToString("yyyyMMdd"); DateTime start = DateTime.Now.AddDays(-5); DateTime end = DateTime.Now.AddMinutes(-1); int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/ActivateRecordId.txt"))); IQueryable acts = spdb.ActivateRecord.Where(m => m.Id >= StartId && m.CreateDate >= start && m.CreateDate < end && m.Status == 1).OrderByDescending(m => m.Id).Take(20); foreach (ActivateRecord act in acts.ToList()) { PosPushDataNewHelper.Deposit(act); ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id); if (edit != null) { edit.Status = 2; } } spdb.SaveChanges(); spdb.Dispose(); db.SaveChanges(); db.Dispose(); mpdb.Dispose(); } catch (Exception ex) { function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常"); } Thread.Sleep(1000); } } } }