Example #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            if (System.Diagnostics.Debugger.IsAttached)
            {
                DebugTrace("Starting Service Host as an application.");

                using (ServiceHost serviceHost = new ServiceHost())
                {
                    serviceHost.DebugStart();

                    var exit = false;
                    Console.WriteLine("Press x to exit");
                    do
                    {
                        var cki = Console.ReadKey(true);
                        if (string.Compare("x", new string(cki.KeyChar, 1), true, CultureInfo.InvariantCulture) == 0)
                            exit = true;
                    }
                    while (!exit);

                    serviceHost.DebugStop();
                }
            }
            else
            {
                DebugTrace("Starting Service Host as a service.");

                try
                {
                    var ServicesToRun = new ServiceBase[] { new ServiceHost() };
                    ServiceBase.Run(ServicesToRun);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine($"Caught {ex.GetType().ToString()}, \"{ ex.ToString()}\"");
                    DKKWindowsServiceHostEventSource.Log.Exception(ex);
                }
            }

            DebugTrace("Stopping Service Host.");
        }
Example #2
0
 internal static extern int SetServiceStatus(IntPtr hServiceStatus, ref ServiceHost.SERVICE_STATUS lpServiceStatus);