I have a project that is deployed to production as a windows service. However for local development purposes it would be useful to run it as a console application. At the moment
I suspect your test project was configured as a windows exe, not a console exe. With a windows exe Console.ReadLine
will return immediately.
To have a console exe that works both as a service and at the command line, start it as a service project (in Visual Studio) - and add a check on Environment.UserInteractive
- i.e.
static void Main() {
if(Environment.UserInteractive) {
// code that starts the listener and waits on ReadLine
} else {
// run the service code that the VS template injected
}
}
You can of course also use a command line switch. I have example on microsoft.public.dotnet.languages.csharp that acts as:
depending on the switches