protected void Abort(List <NagNode> nagNodes)
 {
     if (nagNodes != null)
     {
         ThreadPoolHelperWithParam <List <NagNode> > .Execute(AbortThread, nagNodes);
     }
 }
        // temp. for testing
        /// <summary>
        /// Launches the test.
        /// </summary>
        /// <returns></returns>
        public static int LaunchTest2()
        {
            GoBoard    lGoBoard    = new GoBoard(9);
            GameRecord lGameRecord = new GameRecord();

            SGFCollection lSGFCollection = new SGFCollection();

            lSGFCollection.LoadSGFFromMemory(SGFGameSamples.DYER);
            lSGFCollection.RetrieveGame(lGameRecord);
            GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, false);

            lGoBoard.Dump();

            PatternCollection lPatternCollection = new PatternCollection(@"Patterns\test.db");

            NagCoordinator lNagCoordinator = new NagCoordinator(9999, lPatternCollection);

            lNagCoordinator.Initialize(lGoBoard);
            ThreadPoolHelperWithParam <int> .Execute(LaunchWorker, 9999);

            ThreadPoolHelperWithParam <int> .Execute(LaunchWorker, 9999);

            ThreadPoolHelperWithParam <int> .Execute(LaunchWorker, 9999);

            ThreadPoolHelperWithParam <int> .Execute(LaunchWorker, 9999);

            Thread.Sleep(1000 * 1);

            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);


            Thread.Sleep(1000 * 300);

            return(0);
        }
        public void ProcesLine(string line)
        {
            if (line == null)
            {
                Disconnect();
                return;
            }

            string lLine = line.TrimEnd('\n');

            string[] lCmds    = lLine.Split('\t');
            bool     lAsync   = (lCmds[0][0] == '!');
            bool     lSuccess = (lCmds[0][lAsync ? 1 : 0] == '=');

            string[] lID         = lCmds[1].Split('.');
            int      lCommandNbr = Convert.ToInt32(lID[0]);
            int      lSeqNbr     = Convert.ToInt32(lID[1]);

            if ((Verbose) && (lCmds.Length > 3))
            {
                Console.Error.WriteLine("STATUS: P< " + lLine);
            }

            lock (this)
            {
                if ((lCommandNbr == 0) && (lSeqNbr == 0) && (!lSuccess))
                {
                    // worker disconnecting...
                    Disconnect();
                    return;
                }

                if (State == ConnectionState.Negotiating)
                {
                    if ((!lSuccess) || (lCmds[2] != "1.0"))
                    {
                        Disconnect();
                        return;
                    }

                    if (lSeqNbr == 1)
                    {
                        State = ConnectionState.Negotiated;
                        ThreadPoolHelperWithParam <WorkerProxy> .Execute(NagCoordinator.WorkerNegotiated, this);

                        //NagCoordinator.WorkerNegotiated(this);
                    }
                }
                else if (State == ConnectionState.SendingPatterns)
                {
                    if (CommandNbr == lCommandNbr)
                    {
                        if (!lSuccess)
                        {
                            Disconnect();
                            return;
                        }

                        if (lSeqNbr == 1)
                        {
                            State = ConnectionState.Available;
                            ThreadPoolHelperWithParam <WorkerProxy> .Execute(NagCoordinator.WorkerAvailable, this);

                            //NagCoordinator.WorkerAvailable(this);
                        }
                    }
                }
                else if (State == ConnectionState.Initializing)
                {
                    if (CommandNbr == lCommandNbr)
                    {
                        if (!lSuccess)
                        {
                            // error with commands, disconnect to reset worker
                            Disconnect();
                            return;
                        }

                        if (lSeqNbr == 1)
                        {
                            State = ConnectionState.Ready;
                            ThreadPoolHelperWithParam <WorkerProxy> .Execute(NagCoordinator.WorkerReady, this);

                            //						NagCoordinator.WorkerReady(this);
                        }
                    }
                }
                else if (State == ConnectionState.Thinking)
                {
                    if (CommandNbr == lCommandNbr)
                    {
                        if (!lSuccess)
                        {
                            // error with commands, disconnect to reset worker
                            Disconnect();
                            return;
                        }

                        if ((lSeqNbr == 6) && (lAsync))
                        {
                            State = ConnectionState.Ready;
                            if (NagNode != null)
                            {
                                NagNode.SetResult(Convert.ToInt32(lCmds[3]), CoordinateSystem.At(lCmds[2], BoardSize));
                                ThreadPoolHelperWithParam <NagNode> .Execute(NagCoordinator.WorkerResult, NagNode);

                                NagNode = null;
                            }

                            ThreadPoolHelperWithParam <WorkerProxy> .Execute(NagCoordinator.WorkerReady, this);
                        }
                    }
                }
                else if (State == ConnectionState.Aborting)
                {
                    if (CommandNbr == lCommandNbr)
                    {
                        if (!lSuccess)
                        {
                            // error with commands, disconnect to reset worker
                            Disconnect();
                            return;
                        }

                        if (lSeqNbr == 1)
                        {
                            State   = ConnectionState.Ready;
                            NagNode = null;
                            ThreadPoolHelperWithParam <WorkerProxy> .Execute(NagCoordinator.WorkerReady, this);
                        }
                    }
                }
            }
        }