Beispiel #1
0
        } // End Constructor

        void DasMulli.Win32.ServiceUtils.IWin32Service.Start(
            string[] startupArguments
            , DasMulli.Win32.ServiceUtils.ServiceStoppedCallback serviceStoppedCallback)
        {
            // in addition to the arguments that the service has been registered with,
            // each service start may add additional startup parameters.
            // To test this: Open services console, open service details, enter startup arguments and press start.
            string[] combinedArguments;
            if (startupArguments.Length > 0)
            {
                combinedArguments = new string[commandLineArguments.Length + startupArguments.Length];
                System.Array.Copy(commandLineArguments, combinedArguments, commandLineArguments.Length);
                System.Array.Copy(startupArguments, 0, combinedArguments, commandLineArguments.Length, startupArguments.Length);
            }
            else
            {
                combinedArguments = commandLineArguments;
            }


            IConfigurationRoot config = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
                                        .AddCommandLine(combinedArguments) // Microsoft.Extensions.Configuration.CommandLine.dll
                                        .Build();

            webHost = new Microsoft.AspNetCore.Hosting.WebHostBuilder()
                      .UseKestrel() // Microsoft.AspNetCore.Server.Kestrel.dll
                      .UseStartup <AspNetCoreStartup>()
                      .UseConfiguration(config)
                      .Build();


            // Make sure the windows service is stopped if the
            // ASP.NET Core stack stops for any reason
            webHost
            .Services
            .GetRequiredService <IApplicationLifetime>()   // Microsoft.Extensions.DependencyInjection
            .ApplicationStopped
            .Register(() =>
            {
                if (this.stopRequestedByWindows == false)
                {
                    serviceStoppedCallback();
                }
            });

            webHost.Start();
        } // End Sub Start
Beispiel #2
0
 public void Listen()
 {
     _webHost.Start();
 }