Exemple #1
0
        private static void PipeServerThread()
        {
            StreamReader sr = new StreamReader(pipeServer);

            try
            {
                int loopCnt = 0;
                do
                {
                    try
                    {
                        pipeServer.WaitForConnection();
                        string input = sr.ReadLine();

                        if (view != null)
                        {
                            view.HandleInput(input);
                        }
                    }
                    catch (Exception)
                    { }
                    if (pipeServer != null)
                    {
                        try
                        {
                            pipeServer.WaitForPipeDrain();
                            if (pipeServer.IsConnected)
                            {
                                pipeServer.Disconnect();
                            }
                        }
                        catch (Exception)
                        { }
                    }
                    Thread.Sleep(10);

                    if (++loopCnt > 10)
                    {
                        loopCnt = 0;

                        lock (pipeServerLock)
                        {
                            try
                            {
                                sr.Close();
                            }
                            catch { }
                            try
                            {
                                CreatePipeServer();
                            }
                            catch { }
                        }
                    }
                } while (pipeServer != null);
            }
            catch (Exception)
            {
            }
        }