Exemplo n.º 1
0
        /// <summary>
        /// 任务处理
        /// </summary>
        /// <returns></returns>
        public int ProessTask()
        {
            int res = 0;
            //TasksBLL tasksbll = new TasksBLL();
            int    resnum = TasksBLL.CountByStatus();
            int    intval = 0;
            Random r      = new Random();

            while (resnum > 0)
            {
                intval++;
                List <TaskSch> list = TasksBLL.GetTasksList("waiting", 1);
                if (list != null && list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        string mobileIndex = "";
                        mobileIndex = item.MobileIndex.ToString();  //需要匹配出对应的客户端标识

                        int flag = 0;
                        for (int i = 0; i < item.RepeatNums; i++)
                        {
                            flag = SocketServer.SendTaskInstruct(Int32.Parse(mobileIndex), item.TypeId, item.Id, item.Bodys);
                            int waittime = r.Next(item.RandomMins, item.RandomMaxs);
                            Thread.Sleep(waittime);
                        }

                        TasksBLL.UpdateTaskStatus(item.Id, flag);
                        resnum--;
                    }
                }
                if (resnum <= 0)
                {
                    resnum = TasksBLL.CountByStatus();
                }
            }
            ConfigVals.IsRunning = 0;
            return(res);
        }