当前位置: 首页>>代码示例>>C#>>正文


C# NamedPipeServerStream.Disconnect方法代码示例

本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.Disconnect方法的具体用法?C# NamedPipeServerStream.Disconnect怎么用?C# NamedPipeServerStream.Disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Pipes.NamedPipeServerStream的用法示例。


在下文中一共展示了NamedPipeServerStream.Disconnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Listen

        private static void Listen()
        {
            NamedPipeServerStream pipeServer =
                new NamedPipeServerStream(MyPipeName,
                                          PipeDirection.In,
                                          1,
                                          PipeTransmissionMode.Message,
                                          PipeOptions.None);

            StreamReader sr = new StreamReader(pipeServer);

            do
            {
                pipeServer.WaitForConnection();
                string fileName = sr.ReadLine();

                Console.WriteLine(fileName);

                Process proc = new Process();
                proc.StartInfo.FileName = fileName;
                proc.StartInfo.UseShellExecute = true;
                proc.Start();

                pipeServer.Disconnect();
            } while (true);
        }
开发者ID:baracchande,项目名称:FileTagger,代码行数:26,代码来源:Program.cs

示例2: StartInternal

        private async void StartInternal(CancellationToken cancellationToken)
        {
            byte[] buffer = new byte[256];
            var commandBuilder = new StringBuilder();

            var serverStream = new NamedPipeServerStream(this.PipeName, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 0, 0);

            using (cancellationToken.Register(() => serverStream.Close()))
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    await Task.Factory.FromAsync(serverStream.BeginWaitForConnection, serverStream.EndWaitForConnection, TaskCreationOptions.None);

                    int read = await serverStream.ReadAsync(buffer, 0, buffer.Length);
                    commandBuilder.Append(Encoding.ASCII.GetString(buffer, 0, read));

                    while (!serverStream.IsMessageComplete)
                    {
                        read = serverStream.Read(buffer, 0, buffer.Length);
                        commandBuilder.Append(Encoding.ASCII.GetString(buffer, 0, read));
                    }

                    var response = this.HandleReceivedCommand(commandBuilder.ToString());
                    var responseBytes = Encoding.ASCII.GetBytes(response);
                    serverStream.Write(responseBytes, 0, responseBytes.Length);

                    serverStream.WaitForPipeDrain();
                    serverStream.Disconnect();

                    commandBuilder.Clear();
                }
            }
        }
开发者ID:RipleyBooya,项目名称:SyncTrayzor,代码行数:33,代码来源:IpcCommsServer.cs

示例3: Run

        internal void Run()
        {
            // Create pipe instance
            using (var pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, 4))
            {
                Console.WriteLine("[SJPS] Thread created");
                // wait for connection
                Console.WriteLine("[SJPS] Waiting for connection");
                pipeServer.WaitForConnection();
                Console.WriteLine("[SJPS] Client has connected");
                IsRunning = true;
                pipeServer.ReadTimeout = 1000;

                // Stream for the request.
                var sr = new StreamReader(pipeServer);
                // Stream for the response.
                var sw = new StreamWriter(pipeServer) {AutoFlush = true};

                while (IsRunning)
                {
                    try
                    {
                        // Read request from the stream.
                        var echo = sr.ReadLine();
                        Console.WriteLine("[SJPS] Recieved request: " + echo);

                        if (echo == "Close")
                        {
                            IsRunning = false;
                            break;
                        }

                        try
                        {
                            ParseRequest(echo);
                            sw.WriteLine("Ack");
                        }
                        catch (Exception)
                        {
                            sw.WriteLine("Error");
                        }
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine("[SJPS] Error: {0}", e.Message);
                        IsRunning = false;
                    }
                }

                pipeServer.Disconnect();
                pipeServer.Close();
            }
        }
开发者ID:OronDF343,项目名称:Sky-Jukebox,代码行数:53,代码来源:PipeServer.cs

示例4: ServerThread

    private static void ServerThread(object data)
    {
        //Creamos el pipe
        NamedPipeServerStream pipeServer =
            new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);

        Console.WriteLine(StringResources.ServidorIniciado);
        while (true)
        {
            Console.WriteLine(StringResources.EsperandoConexion);
            //Esperamos conexiones
            pipeServer.WaitForConnection();
            Console.WriteLine(StringResources.ClienteConectado);

            try
            {
                //Creamos un StreamString usando el pipe
                StreamString ss = new StreamString(pipeServer);

                //Recibimos el comando del cliente a través del Pipe
                string command = ss.ReadString();
                Console.WriteLine(StringResources.ComandoRecibido+":"+command);
                //Ejecutamos el proceso,redirigiendo la salida al pipe
                ProcessStartInfo pinfo = new ProcessStartInfo();
                pinfo.UseShellExecute = false;
                pinfo.RedirectStandardOutput = true;
                pinfo.FileName= ConfigurationManager.AppSettings.Get("powershellPath");
                pinfo.Arguments = '"'+command+ '"';
                using(Process process = Process.Start(pinfo))
                {
                    using (StreamReader reader = process.StandardOutput)
                    {
                        String line = reader.ReadLine();
                        while ( line != null )
                        {
                            ss.WriteString(line);
                            line = reader.ReadLine();
                        }

                        ss.WriteString("##END##");
                        Console.WriteLine(StringResources.ComandoTerminado);
                    }
                }
                           }
            // Catch the IOException that is raised if the pipe is broken
            // or disconnected.
            catch (IOException e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
            }
            pipeServer.Disconnect();
        }
    }
开发者ID:Junquer-G,项目名称:AuditWare,代码行数:53,代码来源:Servidor.cs

示例5: ExecuteThread

        private static void ExecuteThread()
        {
            Debug.WriteLine("\n*** Named pipe server stream starting (" + Program.PROCESS_PIPE_NAME + ") ***\n");

            var pipeServer = new NamedPipeServerStream(Program.PROCESS_PIPE_NAME, PipeDirection.InOut, 1);
            int threadId = Thread.CurrentThread.ManagedThreadId;

            while (run)
            {
                pipeServer.WaitForConnection();

                try
                {
                    StreamString ss = new StreamString(pipeServer);
                    var incoming = ss.ReadString();

                    Debug.WriteLine("Incoming command from pipe: " + incoming);
                    ss.WriteString("OK");
                    pipeServer.Disconnect();

                    if (incoming.Length <= 0)
                    {
                        continue;
                    }

                    string[] commandParts = incoming.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    CommandProcessor.Process(commandParts);
                }
                catch (IOException e)
                {
                    Debug.WriteLine("\n*** ERROR - Named pipe server stream failed, exception details follow [will try to continue] (" + Program.PROCESS_PIPE_NAME + ") ***\n\n {0} \n\n", e.Message);

                    try
                    {
                        pipeServer.Disconnect();
                    }
                    catch (Exception) { }
                }
            }
        }
开发者ID:roydejong,项目名称:MultiClip,代码行数:40,代码来源:PipeServer.cs

示例6: ConnectToService

        /// <summary>
        /// Connect from core to the service - used in core to listen for commands from the service
        /// </summary>
        public static void ConnectToService()
        {
            if (connected) return; //only one connection...

            Async.Queue("MBService Connection", () =>
            {
                using (NamedPipeServerStream pipe = new NamedPipeServerStream(MBSERVICE_OUT_PIPE,PipeDirection.In))
                {
                    connected = true;
                    bool process = true;
                    while (process)
                    {
                        pipe.WaitForConnection(); //wait for the service to tell us something
                        try
                        {
                            // Read the request from the service.
                            StreamReader sr = new StreamReader(pipe);

                            string command = sr.ReadLine();
                            switch (command.ToLower())
                            {
                                case IPCCommands.ReloadItems:
                                    //refresh just finished, we need to re-load everything
                                    Logger.ReportInfo("Re-loading due to request from service.");
                                    Application.CurrentInstance.ReLoad();
                                    break;
                                case IPCCommands.Shutdown:
                                    //close MB
                                    Logger.ReportInfo("Shutting down due to request from service.");
                                    Application.CurrentInstance.Close();
                                    break;
                                case IPCCommands.CloseConnection:
                                    //exit this connection
                                    Logger.ReportInfo("Service requested we stop listening.");
                                    process = false;
                                    break;

                            }
                            pipe.Disconnect();
                        }
                        catch (IOException e)
                        {
                            Logger.ReportException("Error in MBService connection", e);
                        }
                    }
                    pipe.Close();
                    connected = false;
                }
            });
        }
开发者ID:bartonnen,项目名称:MediaBrowser.Classic,代码行数:53,代码来源:MBServiceController.cs

示例7: createPipeServer

        public static void createPipeServer()
        {
            Decoder decoder = Encoding.Default.GetDecoder();
            Byte[] bytes = new Byte[BufferSize];
            char[] chars = new char[BufferSize];
            int numBytes = 0;
            StringBuilder msg = new StringBuilder();

            try
            {
                pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.In, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
                while (true)
                {
                    pipeServer.WaitForConnection();

                    do
                    {
                        msg.Length = 0;
                        do
                        {
                            numBytes = pipeServer.Read(bytes, 0, BufferSize);
                            if (numBytes > 0)
                            {
                                int numChars = decoder.GetCharCount(bytes, 0, numBytes);
                                decoder.GetChars(bytes, 0, numBytes, chars, 0, false);
                                msg.Append(chars, 0, numChars);
                            }
                        } while (numBytes > 0 && !pipeServer.IsMessageComplete);
                        decoder.Reset();
                        if (numBytes > 0)
                        {
                            //Notify the UI for message received
                            if (owner != null)
                                owner.Dispatcher.Invoke(DispatcherPriority.Send, new Action<string>(owner.OnMessageReceived), msg.ToString());
                            //ownerInvoker.Invoke(msg.ToString());
                        }
                    } while (numBytes != 0);
                    pipeServer.Disconnect();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:guozanhua,项目名称:kinect-ripple,代码行数:45,代码来源:MessageSender.cs

示例8: Main

        static void Main()
        {
            string echo = "";
            while (true)
            {
                //Create pipe instance
                NamedPipeServerStream pipeServer =
                new NamedPipeServerStream("testpipe", PipeDirection.InOut, 4);
                Console.WriteLine("[ECHO DAEMON] NamedPipeServerStream thread created.");

                //wait for connection
                Console.WriteLine("[ECHO DAEMON] Wait for a client to connect");
                pipeServer.WaitForConnection();

                Console.WriteLine("[ECHO DAEMON] Client connected.");
                try
                {
                    // Stream for the request.
                    StreamReader sr = new StreamReader(pipeServer);
                    // Stream for the response.
                    StreamWriter sw = new StreamWriter(pipeServer);
                    sw.AutoFlush = true;

                    // Read request from the stream.
                     echo = sr.ReadLine();

                    Console.WriteLine("[ECHO DAEMON] Request message: " + echo);

                    // Write response to the stream.
                    sw.WriteLine("[ECHO]: " + echo);

                    pipeServer.Disconnect();
                }
                catch (IOException e)
                {
                    Console.WriteLine("[ECHO DAEMON]ERROR: {0}", e.Message);
                }

                System.IO.File.WriteAllText(@"C:\Users\tlewis\Desktop\WriteLines.txt", echo);

                pipeServer.Close();
            }
        }
开发者ID:gw-sd-2016,项目名称:Presenting101,代码行数:43,代码来源:Program.cs

示例9: Listen

        //server
        private void Listen(NamedPipeServerStream server, StreamWriter writer)
        {
            var buffer = new byte[4096];

            #region
            //server.BeginRead(buffer, 0, 4096, p =>
            //{
            //    Trace.WriteLine(p.IsCompleted);
            //    server.EndRead(p);
            //    var reader = new StreamReader(server);
            //    var temp = string.Empty;

            //    while (!string.IsNullOrEmpty((temp = reader.ReadLine())))
            //    {
            //        Trace.WriteLine("Server:from client " + temp);
            //        writer.WriteLine("echo:" + temp);
            //        writer.Flush();
            //        break;
            //    }
            //    server.Disconnect();
            //    Listen(server, writer);
            //}, null);
            #endregion

            server.BeginWaitForConnection(new AsyncCallback(o =>
            {
                var pipe = o.AsyncState as NamedPipeServerStream;
                pipe.EndWaitForConnection(o);

                var reader = new StreamReader(pipe);
                var result = reader.ReadLine();
                var text = string.Format("connected:receive from client {0}|{1}", result.Length, result);
                Trace.WriteLine(text);
                writer.WriteLine(result);
                writer.Flush();
                writer.WriteLine("End");
                writer.Flush();

                server.WaitForPipeDrain();
                server.Disconnect();
                Listen(pipe, writer);
            }), server);
        }
开发者ID:yonglehou,项目名称:AppAgent,代码行数:44,代码来源:AppAgentTest.cs

示例10: Main

        static void Main(string[] args)
        {
            while (true)
            {
                //Create pipe instance
                NamedPipeServerStream pipeServer =
                new NamedPipeServerStream("mojotestpipe", PipeDirection.InOut, 4);
                Console.WriteLine(String.Format("[DOTNET] {0} NamedPipeServerStream thread created.", DateTime.Now.ToString("T")));

                //wait for connection
                Console.WriteLine(String.Format("[DOTNET] {0} Wait for a client to connect...", DateTime.Now.ToString("T")));
                pipeServer.WaitForConnection();

                Console.WriteLine(String.Format("[DOTNET] {0} Client connected.", DateTime.Now.ToString("T")));
                try
                {
                    // Stream for the request.
                    StreamReader sr = new StreamReader(pipeServer);
                    // Stream for the response.
                    StreamWriter sw = new StreamWriter(pipeServer);
                    sw.AutoFlush = true;

                    // Read request from the stream.
                    string echo = sr.ReadLine();

                    Console.WriteLine(String.Format("[DOTNET] {0} Request message: {1}", DateTime.Now.ToString("T"), echo));

                    // Write response to the stream.
                    sw.WriteLine("[ECHO]: " + echo);

                    pipeServer.Disconnect();
                }
                catch (IOException e)
                {
                    Console.WriteLine(String.Format("[DOTNET] {0} Error: {1}", DateTime.Now.ToString("T"), e.Message));
                }
                pipeServer.Close();
            }
        }
开发者ID:jagdishRangaswamy,项目名称:cloudera-connector,代码行数:39,代码来源:Program.cs

示例11: pipeServerThread

        void pipeServerThread(object o)
        {
            NamedPipeServerStream pipeServer = null;
            try
            {
                while (true)
                {
                    pipeServer = new NamedPipeServerStream(
                        this.ServerName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

                    IAsyncResult async = pipeServer.BeginWaitForConnection(null, null);
                    int index = WaitHandle.WaitAny(new WaitHandle[] { async.AsyncWaitHandle, closeApplicationEvent });
                    switch (index)
                    {
                        case 0:
                            pipeServer.EndWaitForConnection(async);
                            using (StreamReader sr = new StreamReader(pipeServer))
                            using (StreamWriter sw = new StreamWriter(pipeServer))
                            {
                                this.Recived(this, new ServerReciveEventArgs(sr, sw));
                            }
                            if (pipeServer.IsConnected)
                            {
                                pipeServer.Disconnect();
                            }
                            break;
                        case 1:
                            return;
                    }
                }
            }
            finally
            {
                if (pipeServer != null)
                {
                    pipeServer.Close();
                }
            }
        }
开发者ID:omega227,项目名称:DeanCC,代码行数:39,代码来源:IPCServer.cs

示例12: pipeWorker

        private void pipeWorker ()
        {
            _isRunning = true;
            
            try
            {
                using ( NamedPipeServerStream pipeServer = new NamedPipeServerStream( _pipeName, PipeDirection.In, 4 ) )
                {                     
                    using ( StreamReader reader = new StreamReader( pipeServer ) )
                    {                   
                        while ( true )
                        {
                            if ( _shutDownServer.WaitOne( 500 ) )
                            {
                                break;
                            }

                            pipeServer.WaitForConnection();

                            onMessageReceived( new PipeServerEventArgs( reader.ReadLine(), null ) );

                            pipeServer.Disconnect();
                        }
                    }
                }
            }
            catch ( Exception ex )
            {
                if(!(ex is ThreadAbortException))
                {
                onMessageReceived(new PipeServerEventArgs(null, ex));
                }
            }
            finally
            {
                _isRunning = false;
                _shutDownServerCompleted.Set();
            }
        }
开发者ID:humanosc,项目名称:Work,代码行数:39,代码来源:PipeServer.cs

示例13: StartPipeServer

        public void StartPipeServer()
        {
            serverStream = new NamedPipeServerStream("zjlrcpipe",
                PipeDirection.InOut,
                10,
                PipeTransmissionMode.Message,
                PipeOptions.None);
            serverStream.ReadMode = PipeTransmissionMode.Message;
            Byte[] bytes = new Byte[1024];
            UTF8Encoding encoding = new UTF8Encoding();
            int numBytes;
            while (running)
            {

                serverStream.WaitForConnection();
                string message = "";
                do
                {
                    numBytes = serverStream.Read(bytes, 0, bytes.Length);

                    message += encoding.GetString(bytes, 0, numBytes);
                } while (!serverStream.IsMessageComplete);

                string[] pas = message.Split('|');
                if (null != pas && pas.Length >= 3)
                {
                    if (!(pas[0] == "exit" && pas[1] == "exit" && pas[2] == "exit"))
                        main.Dispatcher.Invoke(main.searchLrcByZLP, pas[0], pas[1], pas[2]);
                    else
                        running = false;
                }

                serverStream.Disconnect();

            }
            serverStream.Dispose();
        }
开发者ID:zhaojunlucky,项目名称:Audio,代码行数:37,代码来源:PipeServer.cs

示例14: PipeListener

 public PipeListener(string pipeName, ISafeCollection<TimePlan> timePlans)
 {
     _timePlans = timePlans;
     _pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Message);
     Task.Run(() =>
     {
         while (true)
         {
             _pipeServer.WaitForConnection();
             using (StreamReader reader = new StreamReader(_pipeServer))
             {
                 using (StreamWriter writer = new StreamWriter(_pipeServer))
                 {
                     try
                     {
                         var req = JsonConvert.DeserializeObject<NewPipeRequest>(reader.ReadToEnd());
                         string[] names = new string[req.RequestPipeCount];//偷懒
                         for (uint i = 0; i < req.RequestPipeCount; i++)
                         {
                             names[i] = Guid.NewGuid().ToString();
                             var instServer = new NamedPipeServerStream(names[i]);
                             OnAttachServer(instServer);
                         }
                     }
                     catch (Exception)
                     {
                         writer.Write(new NewPipePostBack(null).ToJson());
                     }
                     finally
                     {
                         _pipeServer.Disconnect();
                     }
                 }
             }
         }
     });
 }
开发者ID:SmablDreamon,项目名称:TimeManger,代码行数:37,代码来源:PipeListener.cs

示例15: ShellCommandHandler

 public ShellCommandHandler(CommandHandler cmdHandler)
 {
     pipeServer = new NamedPipeServerStream("sciGitPipe", PipeDirection.In, 1, PipeTransmissionMode.Byte,
                                      PipeOptions.Asynchronous);
       pipeThread = new Thread(() => {
     while (true) {
       try {
     var ar = pipeServer.BeginWaitForConnection(null, null);
     pipeServer.EndWaitForConnection(ar);
     var ss = new StreamString(pipeServer);
     string verb = ss.ReadString();
     string filename = ss.ReadString();
     cmdHandler(verb, filename);
     pipeServer.Disconnect();
       } catch (ObjectDisposedException) {
     break;
       } catch (IOException) {
     break;
       } catch (Exception e) {
     Logger.LogException(e);
       }
     }
       });
 }
开发者ID:SciGit,项目名称:scigit-client,代码行数:24,代码来源:ShellCommandHandler.cs


注:本文中的System.IO.Pipes.NamedPipeServerStream.Disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。