Пример #1
0
        public void SelfHost(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            while (true)
            {
                string program_args = "";

                for (int i = 0; i < args.Length; i++)
                {
                    program_args += args[i] + " ";
                }

                RoboHost h = new RoboHost();
                program_args += "--robo_hosted --robo_port:" + h.Port;
                Process p = Process.Start(System.Windows.Forms.Application.ExecutablePath, program_args.Trim());
                while (!p.WaitForExit(1000 * 10))
                {
                    h.KeepAlives++;
                    // 60 seconds
                    if (h.KeepAlives > 6)
                    {
                        Trace.WriteLine("Client is not alive: " + h.KeepAlives);
                        // the client is not alive.
                        p.Kill();
                    }
                }
                // process has quit

                Trace.WriteLine("Process has quit: " + p.ExitCode);
                if (p.ExitCode == GracefulExitCode)
                {
                    Trace.WriteLine("Application closed gracefully, shutting down.");
                    Environment.Exit(0);
                }
            }
        }
        public void SelfHost(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            while (true)
            {
                string program_args = "";

                for (int i = 0; i < args.Length; i++)
                {
                    program_args += args[i] + " ";
                }

                RoboHost h = new RoboHost();
                program_args += "--robo_hosted --robo_port:" + h.Port;
                Process p = Process.Start(System.Windows.Forms.Application.ExecutablePath, program_args.Trim());
                while (!p.WaitForExit(1000 * 10))
                {
                    h.KeepAlives++;
                    // 60 seconds
                    if (h.KeepAlives > 6)
                    {
                        Trace.WriteLine("Client is not alive: " + h.KeepAlives);
                        // the client is not alive.
                        p.Kill();
                    }
                }
                // process has quit

                Trace.WriteLine("Process has quit: " + p.ExitCode);
                if (p.ExitCode == GracefulExitCode)
                {
                    Trace.WriteLine("Application closed gracefully, shutting down.");
                    Environment.Exit(0);
                }
            }
        }