public void ReRun() { // Assign width and height and other properties this.Width = Graph.Width; this.Height = Graph.Height; // Create thread workers currentWorkers = new List <LiveWireWorker>(); currentWorkersCompleted = new List <bool>(); currentWorkersProgress = new List <int>(); currentProgress = 0; for (int worker = 0; worker < ThreadCount; worker++) { LiveWirePrimaryWorker thread = new LiveWirePrimaryWorker(); thread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(OnWorkerProgressCompleted); thread.ProgressChanged += new ProgressChangedEventHandler(OnWorkerProgressChanged); currentWorkers.Add(thread); currentWorkersCompleted.Add(false); currentWorkersProgress.Add(0); } // Create data objects for workers List <List <LiveWirePrimaryPath> > pathLists = new List <List <LiveWirePrimaryPath> >(); for (int t = 0; t < ThreadCount; t++) { pathLists.Add(new List <LiveWirePrimaryPath>()); } int currentThreadIndex = 0; foreach (LiveWirePrimaryPath p in ReWorkPaths) { // Assign an index to a worker thread pathLists[currentThreadIndex].Add(p); currentThreadIndex = (currentThreadIndex + 1) % ThreadCount; } // Launch workers for (int worker = 0; worker < currentWorkers.Count; worker++) { LiveWirePrimaryWorker w = currentWorkers[worker] as LiveWirePrimaryWorker; w.Mode = LiveWireWorker.WorkMode.ReWork; w.Graph = Graph; w.TerminalCollection = Terminals; w.ReWorkPaths = pathLists[worker]; w.DistanceMap = DistanceMap; w.RunWorkerAsync(); } }
public void Run() { // Assign width and height and other properties this.Width = Graph.Width; this.Height = Graph.Height; // Create thread workers currentWorkers = new List <LiveWireWorker>(); currentWorkersCompleted = new List <bool>(); currentWorkersProgress = new List <int>(); currentProgress = 0; for (int worker = 0; worker < ThreadCount; worker++) { LiveWirePrimaryWorker thread = new LiveWirePrimaryWorker(); thread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(OnWorkerProgressCompleted); thread.ProgressChanged += new ProgressChangedEventHandler(OnWorkerProgressChanged); currentWorkers.Add(thread); currentWorkersCompleted.Add(false); currentWorkersProgress.Add(0); } // Create data objects for workers List <List <Tuple <int, int> > > workerPointPairs = new List <List <Tuple <int, int> > >(); for (int t = 0; t < ThreadCount; t++) { workerPointPairs.Add(new List <Tuple <int, int> >()); } List <Tuple <int, int> > terminalPairs = new List <Tuple <int, int> >(); foreach (RootTerminal sourceTerminal in Terminals.UnlinkedSources) { foreach (RootTerminal tipTerminal in Terminals.UnlinkedPrimaries) { terminalPairs.Add(new Tuple <int, int>(Terminals.IndexOf(sourceTerminal), Terminals.IndexOf(tipTerminal))); } } if (Terminals.TerminalLinks != null && Terminals.TerminalLinks.Count > 0) { foreach (var link in Terminals.TerminalLinks) { terminalPairs.Add(new Tuple <int, int>(Terminals.IndexOf(link.Item1), Terminals.IndexOf(link.Item2))); } } int currentThreadIndex = 0; foreach (Tuple <int, int> terminalPair in terminalPairs) { // Assign patch to a worker thread workerPointPairs[currentThreadIndex].Add(terminalPair); currentThreadIndex = (currentThreadIndex + 1) % ThreadCount; } // Launch workers for (int worker = 0; worker < currentWorkers.Count; worker++) { LiveWirePrimaryWorker w = currentWorkers[worker] as LiveWirePrimaryWorker; w.Mode = LiveWireWorker.WorkMode.Work; w.TerminalPairs = workerPointPairs[worker]; w.TerminalCollection = Terminals; w.Graph = Graph; w.DistanceMap = DistanceMap; w.RunWorkerAsync(); } }