Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.NET 2k5 Windows service timer not triggering

Posted on 2007-11-29
4
Medium Priority
?
4,586 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:
Joel Coehoorn earned 500 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:Joel Coehoorn
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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 .

926 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