1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System;
- using System.Collections.Generic;
- using Library;
- using LitJson;
- using System.Linq;
- using System.Data;
- using System.Threading;
- using MySystem.PxcModels;
- namespace MySystem
- {
- public class MessageCenterService
- {
- public readonly static MessageCenterService Instance = new MessageCenterService();
- private MessageCenterService()
- { }
- public void Start()
- {
- Thread th = new Thread(dosomething);
- th.IsBackground = true;
- th.Start();
- }
- public void dosomething()
- {
- while (true)
- {
- string data = RedisDbconn.Instance.RPop<string>("MsgPersonalQueue");
- if (!string.IsNullOrEmpty(data))
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- MsgPersonal msg = Newtonsoft.Json.JsonConvert.DeserializeObject<MsgPersonal>(data);
- db.MsgPersonal.Add(msg);
- db.SaveChanges();
- db.Dispose();
- }
- catch (Exception ex)
- {
-
- function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "消息中心队列异常");
- }
- }
- else
- {
- Thread.Sleep(60000);
- }
- }
- }
- }
- }
|