示例#1
0
 public void Dispose()
 {
     IsRun            = false;
     OnTaskExecAfter  = null;
     OnTaskExecBefore = null;
     _listTask        = null;
     mainThread       = null;
     _taskManager     = null;
 }
示例#2
0
 public static TasksManage GetInstance()
 {
     if (_taskManager == null)
     {
         lock (_lockobj)
         {
             if (_taskManager == null)
             {
                 _taskManager = new TasksManage();
             }
         }
     }
     return(_taskManager);
 }
示例#3
0
        public void StartUp(Func <int, bool> HeartAction, Func <int> QueryUseServerAction)
        {
            if (mainThread == null)
            {
                mainThread = new Thread(new ThreadStart(delegate()
                {
                    while (IsRun)
                    {
                        if (!TasksManage.GetInstance().CheckIsRun())//发现执行任务的线程没有执行,则停止当前线程,可以重新分配任务
                        {
                            IsRun = false;
                            if (OnDeadServer != null)
                            {
                                OnDeadServer(ServerCount - 1, ServerCount);
                            }
                            return;
                        }
                        HeartAction(MyServer.Id);    //心跳记录
                        int nowServerCount = QueryUseServerAction();
                        if (nowServerCount != ServerCount)
                        {
                            if (nowServerCount < ServerCount)
                            {
                                if (OnDeadServer != null)
                                {
                                    OnDeadServer(nowServerCount, ServerCount);
                                }
                            }
                            if (OnServerCountChange != null)
                            {
                                OnServerCountChange(MyServer.Id);
                            }
                            //服务器有变动
                        }
                        ServerCount = nowServerCount;

                        Thread.Sleep(1000 * 60 * AppConfig.ServerHeartInterval);//休息n分钟后再执行
                    }
                }));

                mainThread.IsBackground = false;
            }
            IsRun = true;
            mainThread.Start();
        }