/// <summary> /// 每隔固定时间,将队列第一个分配任务 /// </summary> private void ThreadHdlVpsEndPoint() { while (_taskSchedule_threadStart) { try { _taskSchedule_Interval = Convert.ToInt32(IpTaskInterval.Text); } catch (Exception) { _taskSchedule_Interval = 500; } int hdlCount = 0; if (_taskAllocatePause) { Thread.Sleep(200); continue; } var ticker = new Win32.HiperTicker(); ticker.Record(); for (int index = 1; index <= _taskSchedule_DefaultInQueueCount; index++) { string vps = string.Empty; if (hdlVpsTaskScheduleQueue.Count == 0) { break; } if (!hdlVpsTaskScheduleQueue.TryDequeue(out vps)) { continue; } ; if (vps != null) { var client = server[vps]; if (client != null) { int taskDelayTime = _taskSchedule_Interval * index - (int)(ticker.Duration / 1000); _dicVpsWorkBeginTime[client.Ip].RecordBegin(taskDelayTime); client.Send(new CmdServerRunScheduleMessage(taskDelayTime)); hdlCount++; } } } hdlCount = hdlCount == 0 ? 1 : hdlCount; Thread.Sleep(_taskSchedule_Interval * (hdlCount)); //Thread.Sleep(500); } _taskSchedule_Start = false; }
private static void ServerBeginRun(int nextRuntimeStamp) { vpsStatus = VpsStatus.Running; if (vpsIsDigging) { Console.WriteLine("警告,同时出现多个采集实例"); return; } vpsIsDigging = true; try { //if (nextRuntimeStamp > 499) Tcp.Send(new RpClientWaitMessage(0, 0, 101));//开始等待 Thread.Sleep(nextRuntimeStamp); //if (nextRuntimeStamp > 499) Tcp.Send(new RpClientWaitMessage(0, 0, -101));//结束等待 // if (servers == null) // { // Console.WriteLine("servers未初始化"); // return; // } var ticker = new Win32.HiperTicker(); ticker.Record(); //Thread.Sleep(60); int hdlGoodNum = servers.ServerRun(); var avgInterval = (int)(ticker.Duration / 1000); // Program.setting.threadSetting.RefreshRunTime((int)(ticker.Duration / 1000)); //TODO 此处估价似乎也有延迟 Program.Tcp?.Send(new RpClientWaitMessage(avgInterval, hdlGoodNum, 0)); } catch (Exception ex) { Console.WriteLine($"处理日程失败;{ex.Message}\n{ex.StackTrace}"); } finally { vpsIsDigging = false; } }