private void GenerateSegmentsThread() { PathGenerationStateChangeEvent args = null; while (m_running) { Tuple <RobotParams, RobotPath> entry = null; lock (m_lock) { if (m_queue.Count > 0) { entry = m_queue[0]; m_queue.RemoveAt(0); m_active = true; } else { entry = null; m_active = false; } args = null; int running = m_active ? 1 : 0; int queued = m_queue.Count; if (running > 0 || queued > 0 || !m_last_event_idle) { args = new PathGenerationStateChangeEvent(running, queued); if (running == 0 && queued == 0) { m_last_event_idle = true; } else { m_last_event_idle = false; } } } if (args != null) { OnJobStateChanged(args); } if (entry != null) { GenerateSegmentsForPath(entry.Item1, entry.Item2); } else { Thread.Sleep(20); } } }
public void GenerateSegments(RobotParams robot, RobotPath path) { PathGenerationStateChangeEvent args = null; Tuple <RobotParams, RobotPath> entry = new Tuple <RobotParams, RobotPath>(robot, path); lock (m_lock) { m_queue.Add(entry); int running = m_active ? 1 : 0; int queued = m_queue.Count; args = new PathGenerationStateChangeEvent(running, queued); } OnJobStateChanged(args); }
protected void OnJobStateChanged(PathGenerationStateChangeEvent args) { EventHandler <PathGenerationStateChangeEvent> handler = StateChanged; handler?.Invoke(this, args); }