コード例 #1
0
        void RunThreadProc()
        {
LABEL_RESTART:
            StartEvent.Reset();
            try
            {
                Console.WriteLine($"DebugHost: Starting the child process '{this.CmdLine}' ...");
                Console.WriteLine("DebugHost: --------------------------------------------------------------");

                using (Process p = Utils.ExecProcess(this.CmdLine))
                {
                    CurrentRunningProcessId = p.Id;

                    StatusManager.SetStatus(Status.Running);

                    try
                    {
                        p.WaitForExit();
                    }
                    finally
                    {
                        CurrentRunningProcessId = 0;
                    }

                    Console.WriteLine("DebugHost: --------------------------------------------------------------");
                    Console.WriteLine($"DebugHost: Exit code of the process: {p.ExitCode}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("DebugHost: --------------------------------------------------------------");
                Console.WriteLine($"DebugHost: {ex.ToString()}");
                Console.WriteLine("DebugHost: --------------------------------------------------------------");
            }

            StatusManager.SetStatus(Status.Stopped);

            Console.WriteLine("DebugHost: The process is stopped. Waiting for next start command ...");

            if (StartEvent.WaitOne(0) == false)
            {
                CancellationTokenSource cancelSource = new CancellationTokenSource();

                Thread waitKeyThread = new Thread(WaitKeyThreadProc);
                waitKeyThread.Start(cancelSource.Token);

                StartEvent.WaitOne();

                cancelSource.Cancel();
                waitKeyThread.Join();
            }

            goto LABEL_RESTART;
        }
コード例 #2
0
        public Host(string cmdLine)
        {
            this.CmdLine = cmdLine;

            StatusManager.SetStatus(Status.Initializing);

            Thread thread = new Thread(RunThreadProc);

            thread.Start();

            CurrentThread = thread;
        }