Solved

VB.NET 2k5 Windows service timer not triggering

Posted on 2007-11-29
4
4,574 Views
Last Modified: 2013-11-26
Hi,

I have written a simple windows service that starts a timer in the OnStart event, the timer.Tick handler then performs the main service code every interval x.
I have the service installed under windows and I can attach the debugger, it is all working as expected except for this quirk (both with debugger attached, and not):
The timer only fires while the app is in the OnStart sub ie. this code fires the timer handler 3 times and no more (GiveTime is just a loop of DoEvents):

    Protected Overrides Sub OnStart(ByVal args() As String)
        tMain.Interval = 3000
        tMain.Enabled = True
        MyFuncs.GiveTime(9)
    End Sub

This code never fires the handler at all:
    Protected Overrides Sub OnStart(ByVal args() As String)
        tMain.Interval = 3000
        tMain.Enabled = True
    End Sub

My conclusion at this point is that the timer stops firing it's 'tick' event as soon as OnStart has completed and from what I understand this should not happen. Any ideas on this are welcome
0
Comment
Question by:Alw1n
[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
4 Comments
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 125 total points
ID: 20375476
.Net includes two completely separate timers:  system.windows.forms.timer and system.timers.timer.  You're probably using a forms timer, which is somewhat bound to the UI thread.  Try using a system.timers.timer instead.  It works pretty much the same, but has an elapsed event instead of a tick event.
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20375493
One more thing to add:  make sure your timer is defined in a place that doesn't go out of scope when your OnStart method has finished.
0
 
LVL 5

Expert Comment

by:mydasx
ID: 20375645
this is a scope problem.  System.Timers.Timer when started, runs in its own thread.  So your concept will work in this context.  Your issue seems to be that the timer is losing scope at the end of the method.  Where and how are you instantiating your timer?
0
 

Author Comment

by:Alw1n
ID: 20380356
Thank you. I was using the forms timer, the system timer works just fine.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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