Disclaimer: I am a consultant at Amazon Web Services, and this is my personal blog. The opinions expressed here are solely mine and do not reflect the views of Amazon Web Services (AWS). Any statements made should not be considered official endorsements or statements by AWS.
To debug a window service you can make use of below property of Environment class:
Environment.UserInteractive
When you run your code in debug mode, this property returns true because your code is running in user interactive mode but when you run your window service as a windows process or service, then this property returns false.
It is recommended to do not show any popup, alert or dialog when this service runs as windows process.
static void Main(string[] args)
{
if (Environment.UserInteractive)
{
// Your own logic to debug
MyService myService = new MyService();
myService.SomeTestMethod();
}
else
{
// Actual window service code
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new InvoiceProcessor()
};
ServiceBase.Run(ServicesToRun);
}
}