C
Chris Hayes
I'm trying to create a nifty Windows Service that will perform tasks at a
predetermined interval.
To make sure I understand the timing correctly I have set an emailer utility
to email me on the start and stop of the service...this works fine. However,
I am trying to test the "ticking" of the timer control and have an emailer
in the sub that handles the timer tick, unfortunately it does not appear to
be ticking...
Can anyone tell me what I'm doing wrong here? (Code below)
Thanks Chris,
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.
'load settings xml file
Dim xmlSettings As New XmlDocument()
xmlSettings.Load("c:\carrotink\nexus\nexusservice\settings.xml")
'set connection string carrot patch node
Dim nodeConnectionStringCarrotPatch As XmlNode =
xmlSettings.DocumentElement.SelectSingleNode("./settings/connectionStrings/c
arrotPatch")
'set connection string commerce node
Dim nodeConnectionStringCommerce As XmlNode =
xmlSettings.DocumentElement.SelectSingleNode("./settings/connectionStrings/c
ommerce")
'set smtp server node
Dim nodeSMTPServer As XmlNode =
xmlSettings.DocumentElement.SelectSingleNode("./settings/notification/smtpSe
rver")
'set smtp server node
Dim nodeEmailSender As XmlNode =
xmlSettings.DocumentElement.SelectSingleNode("./settings/notification/emailS
ender")
'instantiate settings object
_settings = New NexusService.Settings(nodeSMTPServer.InnerText,
nodeEmailSender.InnerText, nodeConnectionStringCarrotPatch.InnerText,
nodeConnectionStringCommerce.InnerText)
'start the timer
timerMain.Interval = 5000
timerMain.Enabled = True
timerMain.Start()
'send an email that service has started
Dim notifier As New NexusService.Notification(Me.Settings)
notifier.Email.Notify("chris", "Service - STARTED - " + Now(), "Service -
STARTED at " + Now(), Web.Mail.MailPriority.Normal)
End Sub
Private Sub timerMain_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles timerMain.Tick
Dim notifier As New NexusService.Notification(Me.Settings)
notifier.Email.Notify("chris", "Service RUNNING - " + Now(), "Service -
RUNNING at " + Now(), Web.Mail.MailPriority.Normal)
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
timerMain.Stop()
Dim notifier As New NexusService.Notification(Me.Settings)
notifier.Email.Notify("chris", "STOPPED - " + Now(), "Service - STOPPED at "
+ Now(), Web.Mail.MailPriority.Normal)
End Sub
predetermined interval.
To make sure I understand the timing correctly I have set an emailer utility
to email me on the start and stop of the service...this works fine. However,
I am trying to test the "ticking" of the timer control and have an emailer
in the sub that handles the timer tick, unfortunately it does not appear to
be ticking...
Can anyone tell me what I'm doing wrong here? (Code below)
Thanks Chris,
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.
'load settings xml file
Dim xmlSettings As New XmlDocument()
xmlSettings.Load("c:\carrotink\nexus\nexusservice\settings.xml")
'set connection string carrot patch node
Dim nodeConnectionStringCarrotPatch As XmlNode =
xmlSettings.DocumentElement.SelectSingleNode("./settings/connectionStrings/c
arrotPatch")
'set connection string commerce node
Dim nodeConnectionStringCommerce As XmlNode =
xmlSettings.DocumentElement.SelectSingleNode("./settings/connectionStrings/c
ommerce")
'set smtp server node
Dim nodeSMTPServer As XmlNode =
xmlSettings.DocumentElement.SelectSingleNode("./settings/notification/smtpSe
rver")
'set smtp server node
Dim nodeEmailSender As XmlNode =
xmlSettings.DocumentElement.SelectSingleNode("./settings/notification/emailS
ender")
'instantiate settings object
_settings = New NexusService.Settings(nodeSMTPServer.InnerText,
nodeEmailSender.InnerText, nodeConnectionStringCarrotPatch.InnerText,
nodeConnectionStringCommerce.InnerText)
'start the timer
timerMain.Interval = 5000
timerMain.Enabled = True
timerMain.Start()
'send an email that service has started
Dim notifier As New NexusService.Notification(Me.Settings)
notifier.Email.Notify("chris", "Service - STARTED - " + Now(), "Service -
STARTED at " + Now(), Web.Mail.MailPriority.Normal)
End Sub
Private Sub timerMain_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles timerMain.Tick
Dim notifier As New NexusService.Notification(Me.Settings)
notifier.Email.Notify("chris", "Service RUNNING - " + Now(), "Service -
RUNNING at " + Now(), Web.Mail.MailPriority.Normal)
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
timerMain.Stop()
Dim notifier As New NexusService.Notification(Me.Settings)
notifier.Email.Notify("chris", "STOPPED - " + Now(), "Service - STOPPED at "
+ Now(), Web.Mail.MailPriority.Normal)
End Sub