public static Path GetPath(int id) { lock (PathsCreated) { if (PathsCreated.ContainsKey(id)) { // remove the path from the dictionary and return it Path p = PathsCreated[id]; PathsCreated.Remove(id); return(p); } else { return(null); } } }
public void Run() { PathRequest pr; Path p; while (true) { // check if any paths are requested lock (PathsRequested) { if (PathsRequested.Count == 0) { continue; } // get the first one off the queue if so pr = PathsRequested.Dequeue(); } // generate the path if (pr.Ends == null) { p = Pathfinder.Generate(Collisions, Map, pr.Start, pr.End, pr.Validation); } else { p = Pathfinder.Generate(Collisions, Map, pr.Start, pr.Ends, pr.Validation); } // add the path to the completion dictionary lock (PathsCreated) { PathsCreated.Add(pr.ID, p); } Thread.Sleep(1); } }