示例#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();
        }
示例#3
0
        private string SetupStartInfo(ProcessStartInfo startInfo, bool autoRestart)
        {
            string guid = Guid.NewGuid().ToString().ToLower();
            this.workingDirectory = startInfo.FileName.ParseFilePath(out workProcessName);

            this.processStartInfo = startInfo;
            this.processStartInfo.Arguments = this.processStartInfo.Arguments.AddArgument(PROCESS_ARG_KEY.PIPENAME, guid);
            this.processStartInfo.WorkingDirectory = this.workingDirectory;
            this.processStartInfo.UseShellExecute = false;
            this.processStartInfo.CreateNoWindow = false;
            this.processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;

            this.autoRestartProcess = autoRestart;
            this.clientChannel = new PipeClientChannel(guid);

            return guid;
        }
        public void Test_Constructor()
        {
            PipeClientChannel clientChannel = new PipeClientChannel("testpipe");

            clientChannel.Dispose();
        }