using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; using Common; using Infrastructure; using Model; using Services; public class HaoDaHelper { public readonly static HaoDaHelper Instance = new HaoDaHelper(); private HaoDaHelper() { } public void Start() { Thread th = new Thread(DoWorks); th.IsBackground = true; th.Start(); } public void DoWorks() { while (true) { string content = RedisServer.Cache.RPop("hd:notice:order"); if(!string.IsNullOrEmpty(content)) { DoQueue(content); } else { Thread.Sleep(5000); } } } public void DoQueue(string content) { try { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(content); var tradeService = App.GetService(); tradeService.Add(item); } catch (Exception ex) { Function.WriteLog(DateTime.Now.ToString() + "\n" + ex, "好哒订单入库异常"); } } }