MessageCenterService.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using MySystem.PxcModels;
  8. namespace MySystem
  9. {
  10. public class MessageCenterService
  11. {
  12. public readonly static MessageCenterService Instance = new MessageCenterService();
  13. private MessageCenterService()
  14. { }
  15. public void Start()
  16. {
  17. try
  18. {
  19. dosomething();
  20. }
  21. catch (Exception ex)
  22. {
  23. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "消息中心队列异常");
  24. }
  25. }
  26. public void dosomething()
  27. {
  28. while (true)
  29. {
  30. string data = RedisDbconn.Instance.RPop<string>("MsgPersonalQueue");
  31. if (!string.IsNullOrEmpty(data))
  32. {
  33. try
  34. {
  35. WebCMSEntities db = new WebCMSEntities();
  36. MsgPersonal msg = Newtonsoft.Json.JsonConvert.DeserializeObject<MsgPersonal>(data);
  37. db.MsgPersonal.Add(msg);
  38. db.SaveChanges();
  39. db.Dispose();
  40. }
  41. catch (Exception ex)
  42. {
  43. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "消息中心队列异常");
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }