Example #1
0
        private void PipeThread()
        {
            while (!stopPipeThread)
            {
                try
                {
                    pipeServer = new NamedPipeServerStream("GISGMPXMLPacketSignerPipe", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
                    pipeServer.WaitForConnection();

                    try
                    {
                        stream = new StreamReaderWriter(pipeServer);
                        // жмём руки
                        PoolToPipe("How are you?");
                        if (stream.ReadLine() == "I am Client! ept!")
                        {
                            PoolToPipe(Logger.Instance.GetFullLog());
                            // теперь можно слать текущие сообщения
                            do
                            {
                                Thread.Sleep(0);
                                if (stream.ReadLine() == "Goodbye!")
                                {
                                    pipeServer.Disconnect();
                                }
                            } while (pipeServer.IsConnected);
                        }
                    }
                    catch (Exception E)
                    {
                        Log("Ошибка stream: " + E.Message);
                    }
                    finally
                    {
                        if (stream != null)
                        {
                            stream.Dispose();
                        }
                    }
                }
                catch (Exception E)
                {
                    Log("Ошибка pipeServer: " + E.Message);
                }
                finally
                {
                    if (pipeServer != null)
                    {
                        pipeServer.Dispose();
                    }
                }
            }
        }
Example #2
0
        private void LogServiceThread()
        {
            NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "GISGMPXMLPacketSignerPipe", PipeDirection.InOut, PipeOptions.Asynchronous);

            if (pipeClient.IsConnected != true)
            {
                pipeClient.Connect();
            }

            // Logger.Instance.logToFile = false;
            StreamReaderWriter stream = new StreamReaderWriter(pipeClient);

            if (stream.ReadLine() == "How are you?")
            {
                stream.WriteLine("I am Client! ept!");
                stream.Flush();
                pipeClient.WaitForPipeDrain();

                /*string s = stream.ReadLine();*/

                tbLog.BeginInvoke((MethodInvoker)(() => tbLog.Clear()));

                Logger.Instance.logToFile = false;

                while (pipeClient.IsConnected && !stopLogServiceThread)
                {
                    string str = stream.ReadLine();
                    if (str != String.Empty)
                    {
                        LogAsIs(str);
                    }
                }

                if (pipeClient.IsConnected)
                {
                    stream.WriteLine("Goodbye!");
                    stream.Flush();
                    pipeClient.WaitForPipeDrain();
                }

                pipeClient.Close();
            }
        }