Windows Service Stuck on Starting

I have a newly minted console app that I have made into a Windows service. I will mention that this code is essentially copied from another windowed program to make it run more efficiently on a server. The code works fine.

This service has a task scheduler built into it, again taken from another console app that runs as a service on the same server. It simply calls a couple of routines that get and put data from two disparate ODBC databases. It does this once a minute.

The new service runs fine but the Services snap-in shows it as Starting, never Running. The original service (on the same server) runs fine and shows as Running within a second of starting.

Here is the Run event code for the App:

' Initialize some things to get us started

dim tmrMainLoop as new tmrLoop

' The loop timer must run continuously and fire every second
tmrMainLoop.mode = Timer.ModeMultiple
tmrMainLoop.Period = 1000

' Start things off
InitService

tmrMainLoop.Enabled = True
do
  App.DoEvents
loop

This is standard stuff, and the code for the properly running service is essentially the same. InitService reads a few things from a settings file.

I have tried delays in the beginning of the Run handler, as well as in the loop. I know that the code is running properly otherwise because it logs everything it does, including writing a line to the log file every time the timer fires!

I’m using 2018r2.

Any suggestions are welcome. Thanks.

You can debug the project by starting the IDE as administrator, select run-paused then use sc to create & start the debug exe. This will connect back to the IDE and let you see where it is going wrong.

My guess would be that the settings file is not where you think it is. Special folder->documents is the usual culprit.

Check the Windows log for any error messages, also security and audit for attempts to access unauthorized resources.

Thanks, gents. I’m back at that client today and have a look.

SOLVED!

Somewhere long ago I came across the instructions to switch the App’s Super to ServiceApplication from ConsoleApplication. It seems that I had since forgotten that little tidbit which is not terribly well documented. Once switched all is well.

May the next person with this problem find this posting.