public bool Connect()
        {
            try
            {
                lock (this)
                {
                    var pipe = new NamedPipeClientStream(Host, Name, PipeDirection.InOut, PipeOptions.Asynchronous);
                    pipe.Connect(1000);
                    pipe.ReadMode = PipeTransmissionMode.Message;
                    Pipe          = new PipeConnection(new byte[BufferSize], pipe);

                    pipe = new NamedPipeClientStream(Host, Name + PipeConnection.PUSH_SUFFIX, PipeDirection.InOut, PipeOptions.Asynchronous);
                    pipe.Connect(1000);
                    pipe.ReadMode = PipeTransmissionMode.Message;
                    PushPipe      = new PipeConnection(new byte[BufferSize], pipe);
                }
                BeginPushPipeRead();
                return(true);
            }
            catch
            {
                Dispose();
            }
            return(false);
        }
Exemple #2
0
 protected void BeginPipeRead(PipeConnection conn)
 {
     if (!Running)
     {
         return;
     }
     conn.Pipe.BeginRead(conn.Buffer, 0, conn.Buffer.Length, OnPipeData, conn);
 }
        public void Dispose()
        {
            lock (this)
            {
                Pipe?.Dispose();
                Pipe = null;

                PushPipe?.Dispose();
                PushPipe = null;
            }
        }
Exemple #4
0
        protected void OnPipeConnect(IAsyncResult ar)
        {
            try
            {
                lock (Pipes)
                {
                    if (ListeningPipe != null)
                    {
                        ListeningPipe.EndWaitForConnection(ar);
                        var conn = new PipeConnection(new byte[BufferSize], ListeningPipe);
                        ListeningPipe = null;

                        Pipes.Add(conn.Pipe, conn);

                        BeginPipeRead(conn);
                        Connected?.Invoke(conn);
                    }
                }
            }
            catch { }

            BeginPipeListen();
        }
Exemple #5
0
        protected void OnPipeConnect(IAsyncResult ar)
        {
            var pipe = ar.AsyncState as NamedPipeServerStream;

            try
            {
                pipe.EndWaitForConnection(ar);
            }
            catch
            {
                Stop();
                return;
            }

            if (!Running)
            {
                pipe.Dispose();
                return;
            }
            lock (Pipes)
            {
                var conn = new PipeConnection(new byte[BufferSize], pipe);
                ListeningPipe = null;

                try
                {
                    BeginPipeRead(conn);
                    Pipes.Add(conn.Pipe, conn);
                }
                catch
                {
                    conn.Dispose();
                }
            }

            BeginPipeListen();
        }
Exemple #6
0
 protected void BeginPipeRead(PipeConnection conn) => conn.Pipe.BeginRead(conn.Buffer, 0, conn.Buffer.Length, OnPipeData, conn);