Closed ghost closed 6 years ago
When you run an app directly you can’t use the windows service functionality. It is only available when started from windows‘ service system. The demo application code in this repo checks for command line arguments that are added in the registration.
How does your startup code (Main function) look like?
`namespace MyConsoleWindowsService { public class Program { private static IConfiguration Configuration { get; set; }
static void Main(string[] args)
{
var configBuilder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
Configuration = configBuilder.Build();
var container = IocConfig();
ICommand cmd = container.Resolve<Method1Command>();
var myService = new RunAsService(cmd);
var serviceHost = new Win32ServiceHost(myService);
serviceHost.Run();
Console.WriteLine("---------- PRESS ANY KEY TO EXIT ----------");
Console.ReadKey();
}
} }`
Yeah serviceHost.Run()
will only work when started from the windows service subsystem as described above.
Closing since behaviour is as designed.
Hi Martin,
Am getting the following error while running directly in my console application. have attached an image.
Great library btw. Thanks