Example #1
0
 /// <summary>
 /// 根据用户Id从当前线程队列移除监听客户端
 /// </summary>
 public static void DequeueCometWaitRequest(Guid sendUserId)
 {
     lock (state)
     {
         //根据sendUserId求余获取当前用户所在线程
         int             nThread    = GuidCoveter.CoveterFirstChat(sendUserId) % maxWaitThreads;
         CometWaitThread waitThread = waitThreads[nThread];
         waitThread.DequeueCometWaitRequest(sendUserId);
     }
 }
Example #2
0
        /// <summary>
        /// 初始化处理线程
        /// </summary>
        /// <param name="count">线程数</param>
        public static void CreateThreads(int count)
        {
            for (int i = 0; i < count; i++)
            {
                CometWaitThread waitThread = new CometWaitThread();
                waitThreads.Add(waitThread);
            }

            maxWaitThreads = count;
        }
Example #3
0
        /// <summary>
        /// 接收来自服务端的信息
        /// </summary>
        public void AddNoticeFromServer(SafeCollection <NoticeModel> listNotice)
        {
            foreach (NoticeModel model in listNotice)
            {
                CometWaitThread cometWaitThread = CometThreadPool.GetUserThread(model.ReceiveUserId);

                if (cometWaitThread != null)
                {
                    cometWaitThread.AddNotice(model);
                }
            }
        }
Example #4
0
        /// <summary>
        /// 返回用户所处的线程
        /// </summary>
        public static CometWaitThread GetUserThread(Guid sendUserId)
        {
            //根据sendUserId求余获取当前用户所在线程
            int nThread = GuidCoveter.CoveterFirstChat(sendUserId) % maxWaitThreads;

            if (waitThreads != null)
            {
                CometWaitThread waitThread = waitThreads[nThread];
                return(waitThread);
            }

            return(null);
        }