Exemplo n.º 1
0
        public void run()
        {
            // Create the thread object, passing in the
            // GraphWalkerClientWorker.connect method via a ThreadStart delegate.
            // This does not start the thread.
            GraphWalkerClientWorker worker = new GraphWalkerClientWorker();
            Thread workerThread            = new Thread(worker.connect);

            // Start the thread
            workerThread.Start();

            // Spin for a while waiting for the started thread to become
            // alive:
            while (!workerThread.IsAlive)
            {
                ;
            }

            worker.connectedEvent.WaitOne();

            worker.loadModel(model);
            worker.loadModelEvent.WaitOne();

            worker.start();
            worker.startEvent.WaitOne();

            Type            smallModelType = typeof(SmallModel);
            ConstructorInfo ctor           = smallModelType.GetConstructor(System.Type.EmptyTypes);

            while (true)
            {
                worker.hasNext();
                worker.hasNextEvent.WaitOne();
                if (!worker.isHasNext)
                {
                    break;
                }

                worker.getNext();
                worker.getNextEvent.WaitOne();
                string methodName = (string)worker.getMessage();

                object     instance   = ctor.Invoke(null);
                MethodInfo methodInfo = smallModelType.GetMethod(methodName);
                methodInfo.Invoke(instance, new object[] {});

                worker.getData();
                worker.getDataEvent.WaitOne();
                Console.WriteLine("Data: " + worker.getDataObject().ToString());
            }
            worker.disconnect();
            workerThread.Join();
        }
        public void run()
        {
            // Create the thread object, passing in the
            // GraphWalkerClientWorker.connect method via a ThreadStart delegate.
            // This does not start the thread.
            GraphWalkerClientWorker worker = new GraphWalkerClientWorker ();
            Thread workerThread = new Thread (worker.connect);

            // Start the thread
            workerThread.Start ();

            // Spin for a while waiting for the started thread to become
            // alive:
            while (!workerThread.IsAlive)
                ;

            worker.connectedEvent.WaitOne ();

            worker.loadModel (model);
            worker.loadModelEvent.WaitOne ();

            worker.start ();
            worker.startEvent.WaitOne ();

            Type smallModelType = typeof(SmallModel);
            ConstructorInfo ctor = smallModelType.GetConstructor(System.Type.EmptyTypes);

            while (true) {
                worker.hasNext ();
                worker.hasNextEvent.WaitOne ();
                if (!worker.isHasNext)
                    break;

                worker.getNext ();
                worker.getNextEvent.WaitOne ();
                string methodName = (string)worker.getMessage();

                object instance = ctor.Invoke(null);
                MethodInfo methodInfo = smallModelType.GetMethod(methodName);
                methodInfo.Invoke(instance, new object[]{});

                worker.getData ();
                worker.getDataEvent.WaitOne ();
                Console.WriteLine("Data: " + worker.getDataObject().ToString());
            }
            worker.disconnect();
            workerThread.Join ();
        }