G
Guest
I have created a windows service but am having difficulties handling
exceptions in the OnStart.
What I want to do is if an exeception occurs during any of the code executed
during the OnStart is to log the problem and stop the service.
I've already sorted out the logging of the problem to the event log but the
suggested solution I have implemented for stopping the service does not work.
Currently I declare a ServiceController and set it to the service and then
instruct it to stop but this doesn't work (code snippet below), all that
happens is that the service shows as 'Starting' in the services list.
Anybody have any ideas?
Nathan
Code:
try
'Initalisation code here
Catch ex As Exception
EventLogger.WriteEntry("Error attempting to start Service,
EventLogEntryType.Error)
Dim scm As New ServiceController(Me.ServiceName)
scm.Stop()
End try
exceptions in the OnStart.
What I want to do is if an exeception occurs during any of the code executed
during the OnStart is to log the problem and stop the service.
I've already sorted out the logging of the problem to the event log but the
suggested solution I have implemented for stopping the service does not work.
Currently I declare a ServiceController and set it to the service and then
instruct it to stop but this doesn't work (code snippet below), all that
happens is that the service shows as 'Starting' in the services list.
Anybody have any ideas?
Nathan
Code:
try
'Initalisation code here
Catch ex As Exception
EventLogger.WriteEntry("Error attempting to start Service,
EventLogEntryType.Error)
Dim scm As New ServiceController(Me.ServiceName)
scm.Stop()
End try