473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Timer in a Window Service not "ticking"

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
Nov 20 '05 #1
3 3267
In article <#w**************@TK2MSFTNGP12.phx.gbl>, Chris Hayes wrote:

<snip>

Chris,

Without looking to closely :), it is my guess that your timer is a
System.Windows.Forms.Timer. That will not work without a message pump
on the thread. You will want to use either the System.Timers.Timer or
the System.Threading.Timer.

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #2
Thanks Tom!

I didn't realize that.

Setting it up as a System.Timers.Timer works like a champ!

I hereby proclaim you a guru.

Thanks again,

Chris
"Tom Shelton" <to*@mtogden.com> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
In article <#w**************@TK2MSFTNGP12.phx.gbl>, Chris Hayes wrote:

<snip>

Chris,

Without looking to closely :), it is my guess that your timer is a
System.Windows.Forms.Timer. That will not work without a message pump
on the thread. You will want to use either the System.Timers.Timer or
the System.Threading.Timer.

--
Tom Shelton
MVP [Visual Basic]

Nov 20 '05 #3
"I hereby proclaim you a guru."
(Chris Hayes)
That's nice Tom Shelton... ;-)
"Tom Shelton" <to*@mtogden.com> escreveu na mensagem
news:Ow**************@TK2MSFTNGP09.phx.gbl...
In article <#w**************@TK2MSFTNGP12.phx.gbl>, Chris Hayes wrote:

<snip>

Chris,

Without looking to closely :), it is my guess that your timer is a
System.Windows.Forms.Timer. That will not work without a message pump
on the thread. You will want to use either the System.Timers.Timer or
the System.Threading.Timer.

--
Tom Shelton
MVP [Visual Basic]

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Chul Min Kim | last post by:
Hi, I got a BUS ERROR from one of my company's program. Let me briefly tell our environment. Machine : Sun E3500 (Ultra Sparc II 400Mhz CPU 4EA) OS : Solaris7 Compiler : Sun Workshop...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.