AppMetrics.AgentService.Program.Main C# (CSharp) Method

Main() static private method

The main entry point for the application.
static private Main ( string args ) : void
args string
return void
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                var arg = args[0];

                try
                {
                    if (arg == "-debug")
                    {
                        var service = new AgentServiceClass();
                        service.Start();
                        Thread.Sleep(Timeout.Infinite);
                    }
                    else if (arg == "-install")
                    {
                        InitWorkingArea();

                        if (GetServiceStatus() == null)
                        {
                            ManagedInstallerClass.InstallHelper(new[] {ExePath, "/LogFile="});
                            SetRecoveryOptions(Const.AppName);
                        }
                    }
                    else if (arg == "-uninstall")
                    {
                        if (GetServiceStatus() != null)
                        {
                            ManagedInstallerClass.InstallHelper(new[] { "/u", ExePath, "/LogFile=" });
                        }
                    }
                    else if (arg == "-start")
                    {
                        StartService();
                    }
                    else if (arg == "-config")
                    {
                        SetConfig(args.Skip(1));
                    }
                }
                catch (Exception exc)
                {
                    var message = exc.ToString();
                    ShowMessage(message);
                }
            }
            else
            {
                var servicesToRun = new ServiceBase[]
                    {
                        new AgentServiceClass()
                    };
                ServiceBase.Run(servicesToRun);
            }
        }