示例#1
0
        private void callBack(IAsyncResult aIAsyncResult)
        {
            using (var lPipeServer = (NamedPipeServerStream)aIAsyncResult.AsyncState)
            {
                try
                {
                    lPipeServer.EndWaitForConnection(aIAsyncResult);
                }
                catch (Exception)
                {
                }

                // we have a connection established, time to wait for new ones while this thread does its business with the client
                // this may look like a recursive call, but it is not: remember, we're in a lambda expression
                // if this bothers you, just export the lambda into a named private method, like you did in your question
                startListen();

                if (!lPipeServer.IsConnected)
                {
                    return;
                }

                StreamString lStreamString = new StreamString(lPipeServer);


                string stringData = lStreamString.ReadString();

                lPipeServer.Close();

                if (MessageDelegateEvent != null)
                {
                    MessageDelegateEvent(stringData);
                }
            }
        }
示例#2
0
        public void send(string SendStr, int TimeOut = 10000)
        {
            try
            {
                using (NamedPipeClientStream pipeStream = new NamedPipeClientStream
                                                              (".", mPipeClientName, PipeDirection.Out))
                {
                    pipeStream.Connect(TimeOut);

                    StreamString lStreamString = new StreamString(pipeStream);

                    lStreamString.WriteString(SendStr);
                }
            }
            catch (Exception)
            {
            }
        }