I have a couple of windows services which all have the same problem. In the service manager, the services have the “Running” status, but they aren’t executing after an automatic boot. They’re set to automatically boot up when the system reboots (which happens every Saturday night). If I manually restart the service, it’s behaving as expected. The problem only arises during an automatic restart.
I’m new to Windows Services so I’m not even sure what relevant information to include, but here’s what the boot up code for the service looks like. I’ve edited it slightly as to not reveal company information, but it isn’t reaching the “DoWork” function at all.
Public Class my_service
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Threading.Thread.Sleep(20000)
If My.Settings.DatabaseLocation = "" Then
Me.Stop()
End If
MyTimer.Interval = My.Settings.Timer
MyTimer.Start()
End Sub
Private WithEvents MyTimer As New Timers.Timer
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
MyTimer.Stop()
MyTimer.Close()
End Sub
Private Sub OnElapsed() Handles MyTimer.Elapsed
'Stop Timer
MyTimer.Stop()
DoWork()
'Start Timer
MyTimer.Start()
End Sub
End Class