Timer question



Took a look at the sample code for timers, put it with simple mods in a new
VB.net project for a windows service.
Code I got is as follows:

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.

Dim aTimer As New System.Timers.Timer(10000)

AddHandler aTimer.Elapsed, AddressOf OnTimedEvent)

' Raise the event every time the timer elapses

aTimer.AutoReset = True

aTimer.Enabled = True

End Sub

' Specify what you want to happen when the event is raised.

Private Shared Sub OnTimedEvent(ByVal source As Object, ByVal e As

I will write my event handling code here

End Sub

In the IDE the word ElapsedEventArgs is underlined and I see that Type
ElapsedEventArgs is not defined. Can anyone tell me what's wrong with my
code. This is almost exactly a cut and paste from the MS examples. I<m
working with Framework 1.1 and VS.net 2033

Thanks for any help







Add the following line to the top of your source file:

Imports System.Timers

The reason why ElapsedEventArgs causes a compile error is because it's not
defined. Using the imports statement above will tell the compiler to look in
the "System.Timers" namespace. Alternatively, you could change the event
handler to include the full declaration like so:

Private Shared Sub OnTimedEvent(ByVal source As Object, ByVal e As

Hope this helps,


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question