?
Solved

Windows Service in .NET question

Posted on 2003-03-14
3
Medium Priority
?
290 Views
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 :)
0
Comment
Question by:SirCaleb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
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
0
 
LVL 2

Expert Comment

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

Imports System.Timers
0
 
LVL 2

Author Comment

by:SirCaleb
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).
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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