Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Windows Service in .NET question

Posted on 2003-03-14
Medium Priority
Last Modified: 2012-06-27
I'm writing a windows service in VB.NET and I can't seem to get my Timer_Tick event to fire when the service is running.  I've attached to it while it's in-process but the event NEVER fires.  The timer is enabled and the interval is set to 100ms.

In my Service_OnStart event, I set the Timer.Enabled = True.  I was able to attached to the process and verified that that particular line of code was executing but the event never fires.

I tried creating a windows form in my project and activating the timer on my form from the OnStart event but the Tick event never fired.

Please help :)
Question by:SirCaleb
  • 2

Accepted Solution

rzweifel earned 1000 total points
ID: 8138571
Don't add a timer control. Instead, define a timer object at the class level:
Private myTimer As Timer

'Instantiate the timer in the OnStart event, attach the event handler, set the interval and enable the timer.
Protected Overrides Sub OnStart(ByVal args() As String)
'Instantiate the timer
myTimer = New Timer()

'Add event handler
AddHandler myTimer.Elapsed, New ElapsedEventHandler(AddressOf Me.myTimer_Elapsed)

myTimer.Interval = 100
myTimer.Enabled = True

End Sub

'Event Handler
Private Sub myTimer_Elapsed(ByVal sender As System.Object, ByVal e As ElapsedEventArgs)
'Code to handle timer event

End Sub

Expert Comment

ID: 8138579
I forgot this: You need to add the following line at the beginning:

Imports System.Timers

Author Comment

ID: 8139576
I actually figured it out on my own first but you are pretty much right ... I was creating my Timer control from the Windows Forms components instead of the Windows Components toolbox.

Thanks anyway (points awarded).

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question