Beispiel #1
0
        public void Run()
        {
            //Start listening in new thread (GetContext blocks)
            ThreadPool.QueueUserWorkItem((o) =>
            {
                Console.WriteLine("API server listening on 127.0.0.1:1234...");
                try
                {
                    while (_listener.IsListening)
                    {
                        thread_info new_thread_info = new thread_info();
                        new_thread_info.ctx         = _listener.GetContext();

                        new_thread_info.reset_event = new ManualResetEvent(false);

                        //Console.WriteLine("Starting thread " + this._threads.Count);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(GotRequest), new_thread_info);

                        this._threads.Add(new_thread_info);

                        //check status of finished threads
                        for (int a = 0; a < this._threads.Count; a++)
                        {
                            if (this._threads[a].reset_event.WaitOne(0))
                            {
                                //Console.WriteLine("Closing thread " + a);
                                this._threads.RemoveAt(a);
                            }
                        }
                    }
                }
                catch { }
            });
        }
Beispiel #2
0
        public void Run()
        {
            //Start listening in new thread (GetContext blocks)
            ThreadPool.QueueUserWorkItem((o) =>
            {
                Console.WriteLine("API server listening on 127.0.0.1:1234...");
                try
                {
                    while (_listener.IsListening)
                    {
                        thread_info new_thread_info = new thread_info();
                        new_thread_info.ctx = _listener.GetContext();

                        new_thread_info.reset_event = new ManualResetEvent(false);

                        //Console.WriteLine("Starting thread " + this._threads.Count);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(GotRequest), new_thread_info);

                        this._threads.Add(new_thread_info);

                        //check status of finished threads
                        for (int a=0;a<this._threads.Count;a++) {
                            if (this._threads[a].reset_event.WaitOne(0)) {
                                //Console.WriteLine("Closing thread " + a);
                                this._threads.RemoveAt(a);
                            }
                        }
                    }
                }
                catch { }
            });
        }