private void ListenerMain()
        {
            // Common ThreadStart delegate
            ThreadStart ts = new ThreadStart(this.ServerMain);

            Thread.CurrentThread.IsBackground = true;

            while (true)
            {
                try
                {
                    _pipe = new PipeConnection(m_pipeName, true, m_pipeSecurityDescriptor);

                    //TODO switch to use completion ports
                    // Wait for a client to connect
                    bool connected = _pipe.WaitForConnect();

                    if (!connected)
                    {
                        throw new PipeIOException("Could not connect to the pipe - os returned " + Marshal.GetLastWin32Error());
                    }
                    else
                    {
                        //TODO Consider using ThreadPool.QueueUserWorkItem

                        Thread server = new Thread(ts);
                        server.IsBackground = true;
                        server.Start();
                    }

                    // Wait for the handler to spin up:
                    _event.WaitOne();
                }
                catch (Exception e)
                {
                    e = e;
                }
            }
        }
예제 #2
0
        private void ListenerMain()
        {
            // Common ThreadStart delegate
            ThreadStart ts = new ThreadStart(this.ServerMain);

            Thread.CurrentThread.IsBackground = true;

            while(true)
            {
                try
                {
                    _pipe  = new PipeConnection(m_pipeName, true, m_pipeSecurityDescriptor);

                    //TODO switch to use completion ports
                    // Wait for a client to connect
                    bool connected = _pipe.WaitForConnect();

                    if (!connected)
                    {
                        throw new PipeIOException("Could not connect to the pipe - os returned " + Marshal.GetLastWin32Error());
                    }
                    else
                    {
                        //TODO Consider using ThreadPool.QueueUserWorkItem

                        Thread server = new Thread(ts);
                        server.IsBackground = true;
                        server.Start();
                    }

                    // Wait for the handler to spin up:
                    _event.WaitOne();
                }
                catch(Exception e)
                {
                    e=e;
                }

            }
        }