Exemplo n.º 1
0
        public void Process_Start()
        {
            PipeClientChannel channel = new PipeClientChannel("testPipe");

            ProcessStartInfo processStartInfo = new ProcessStartInfo();
            processStartInfo.FileName = @"C:\Workspace\GitHub\AppProcessManager\bin\WorkerProcess.exe";
            processStartInfo.Arguments = "-pipeName testPipe";
            processStartInfo.UseShellExecute = false;
            processStartInfo.WorkingDirectory = @"C:\Workspace\GitHub\AppProcessManager\bin";
            processStartInfo.CreateNoWindow = false;
            processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            processStartInfo.RedirectStandardOutput = true;

            Task.Run(() => { 
                var process = Process.Start(processStartInfo);
                process.EnableRaisingEvents = true;
                process.OutputDataReceived += Process_OutputDataReceived;
                process.ErrorDataReceived += Process_ErrorDataReceived;
                process.Exited += Process_Exited;

                Console.WriteLine(process.Id);
            });

            Thread.Sleep(10000);

            channel.SendAsyncReceive(CommandMessage.STOP, this.ResponseHandler);
            Console.WriteLine("End of Process_Start");

            Thread.Sleep(1000);
        }
        public void Test_SendMessage()
        {
            PipeClientChannel clientChannel = new PipeClientChannel("testpipe");
            clientChannel.SendAsyncReceive("Hello Server, this is client !", this.ResponseCallback);

            Thread t = new Thread(this.RunPipeServer);
            t.Start();

            Thread.Sleep(1000);

            string response = clientChannel.SendReceive("Hello Server, this is client !");
            Console.WriteLine(response);

            Thread.Sleep(1000);

            clientChannel.Dispose();
        }