OnStart() protected method

protected OnStart ( string args ) : void
args string
return void
Exemplo n.º 1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            var environment = System.Configuration.ConfigurationManager.AppSettings["Environment"].ToString();
            var logFilePath = System.Configuration.ConfigurationManager.AppSettings["LogFilePath"].ToString();

            LogService(String.Format("Environment:   '{0}'", environment));
            LogService(String.Format("Log file path: '{0}'", logFilePath));

            if (Environment.UserInteractive)
            {
                LogService("Running mode:  'Interactive'");

                var service = new Service1();
                service.OnStart(new string[] { "" });

                LogService("NOTE: You can press any key at any time to exit ...");

                Console.ReadLine();
                service.OnStop();
            }
            else
            {
                LogService("Running mode:  'As a Service'");
                var service = new Service1();
                Run(service);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            var svc = new Service1();

            svc.OnStart(args);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var service = new Service1();

            if (Debugger.IsAttached)
            {
                service.OnStart(args);
                Console.WriteLine("Find the any key!");
                Console.Read();
                service.OnStop();
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    service
                };
                ServiceBase.Run(ServicesToRun);
            }
        }