Anil said:
I am having a problem getting the service to start and I cannot debug it.
I installed it on a different computer using installutil.exe In the
Services list, it appears, and I can hit start. However, I get a message
saying something to the effect that ther service started and then stopped
and that this was typical of services that "have nothing to do".
Some thoughts about Services:
When they are started, the Service Control infrastructure calls your
OnStart method. This must return within a fixed time interval, or the
Service gets reported as "failing to start".
Don't call your "main processing" directly from OnStart.
You [normally] have to provide a loop construct to keep the service
running. This doesn't happen automatically as it does in a Windows Forms
app.
If you have large "units of work", watch out for OnStop.
The Service Control infrastructure calls your OnStop routine, which allows
you to "clean up" what the service is doing. When you return from OnStop,
the infrastructure tears down your service process, no matter what it
might still be doing.
Here's how I do it:
Sub OnStart()
tmrStarter.Start()
End Sub
Private Sub tmrStarter_Elapsed( ...
' Kill the Timer - we don't need it again
tmrStarter.Stop()
m_bShutdownComplete = False
Do While Not m_bShutdownRequested
DoProcessing()
System.Threading.Thread.Sleep( a_while )
Loop
m_bShutdownComplete = True
End Sub
Sub OnStop()
m_bShutdownRequested = True
Do While Not m_bShutdownComplete
System.Threading.Thread.Sleep( 1000 )
Loop
' Return from OnStop and your process gets torn down!
End Sub
Private m_bShutdownRequested as Boolean
Private m_bShutdownComplete as Boolean
Private Sub DoProcessing()
' Do the useful work here
' If you have any loop constructs, you can include tests of
' m_bShutdownRequested, so that your service can respond
' quickly to stop requests.
End Sub
HTH,
Phill W.