Example #1
0
        private void ReadPipe()
        {
            bool running = true;

            while (running)
            {
                using (var notifyWait = new NamedPipeServerStream(PipeName, PipeDirection.InOut, 1))
                {
                    notifyWait.WaitForConnection();
                    try
                    {
                        StreamString ss      = new StreamString(notifyWait);
                        string       command = ss.ReadString();
                        ss.WriteString(ProcessCommand(command));
                    }
                    catch (ThreadInterruptedException)
                    {
                        running = false;
                    }
                    catch (IOException e)
                    {
                        logger.Error(e);
                    }
                }
            }
        }
Example #2
0
 public bool Notify()
 {
     using (var client = new NamedPipeClientStream(PipeName))
     {
         client.Connect();
         StreamString ss = new StreamString(client);
         ss.WriteString(ShowCommand);
         return(ss.ReadString() == OkResponse);
     }
 }
Example #3
0
 private void ReadPipe(CancellationToken token)
 {
     using (var notifyServerStream = new NamedPipeServerStream(PipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous))
     {
         token.Register(() =>
         {
             notifyServerStream?.SafePipeHandle.Close();
             notifyServerStream?.Close();
         });
         while (!token.IsCancellationRequested)
         {
             notifyServerStream.WaitForConnection();
             StreamString ss      = new StreamString(notifyServerStream);
             string       command = ss.ReadString();
             ss.WriteString(ProcessCommand(command));
             notifyServerStream.Disconnect();
         }
     }
 }
        private async Task ReadPipe()
        {
            source = new CancellationTokenSource();
            while (!source.IsCancellationRequested)
            {
                using (var notifyWait = new NamedPipeServerStream(PipeName, PipeDirection.InOut, 1))
                {
                    await Task.Run(() => notifyWait.WaitForConnection(), source.Token);

                    try
                    {
                        StreamString ss      = new StreamString(notifyWait);
                        string       command = ss.ReadString();
                        ss.WriteString(ProcessCommand(command));
                    }
                    catch (IOException e)
                    {
                        logger.Error(e);
                    }
                }
            }
        }