天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
1.5 KiB

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QM.Exchange.Interface;
namespace QM.Exchange.Core.Services
{
/// <summary>
/// 服务端时间同步服务
/// </summary>
public class ServerTimeService : IService
{
/// <summary>
/// 运行标志
/// </summary>
private bool _running = false;
public void Start()
{
_running = true;
while (_running)
{
DuplexMessageService dmService = new DuplexMessageService();
//获取客户端会话ID列表
string[] clientIDList = null;
clientIDList = dmService.GetClientList().Keys.ToArray<string>();
//定义消息
CommonMessage msg = new CommonMessage();
msg.MsgID = Guid.NewGuid().ToString();
msg.MsgType = "UpdateSystemTime";
msg.Content = QMFrameWork.Common.Serialization.JsonConvertHelper.GetSerializes(DateTime.Now);
//向所有客户端发送系统时间
for (int i = 0; i < clientIDList.Length; i++)
{
string sessionID = clientIDList[i];
dmService.SendMessageToClient(sessionID, msg);
}
System.Threading.Thread.Sleep(1000);
}
}
public void Stop()
{
_running = false;
}
}
}