Solved

VB.NET 2k5 Windows service timer not triggering

Posted on 2007-11-29
4
4,567 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now