Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.NET 2k5 Windows service timer not triggering

Posted on 2007-11-29
4
Medium Priority
?
4,578 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 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: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

Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

688 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