Пример #1
0
        //tests receiving and responding to QueryRequests
        static void testQueryRequestServer()
        {
            Guid          myGuid = Guid.NewGuid();
            CommandServer cs     = new CommandServer(myGuid);
            int           x      = 0;

            while (cs.ClientThreadCount() == 0)
            {
                x++;
                Thread.Sleep(1000);
                Print("waiting for message. " + x);
            }
            ClientThread ct = cs.getClientThread();

            Print("got client thread.");
            while (ct.EventCount() == 0)
            {
                x++;
                Thread.Sleep(1000);
                Print("waiting to receive request." + x);
            }
            Print("received request.");
            QueryRequest qr = (QueryRequest)ct.DequeueEvent();

            Print("request: " + qr.QueryType);
            ct.RespondToQuery(qr);
            Print("responded to query.");
            while (ct.IsWorking())
            {
                x++;
                Thread.Sleep(1000);
                Print("waiting for ClientThread to finish working." + x);
            }
            ct.RequestStop();
            Print("requested clientthread stop");
            cs.Stop();
            Print("stopped CommandServer.");
            Console.WriteLine("press a key to continue");
            Console.ReadKey();
        }