473,757 Members | 9,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble getting timer tick to fire in Windows Service

Hello,

I'm trying run a process at regular intervals using a windows service. the
problem is, the timer_tick event doesn't appear to be working. I've written
the following code as a test;

Public Class FileName
Protected Overrides Sub OnStart(ByVal args() As String)

Timer1.Interval = 1000
Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick

If Not EventLog.Source Exists("Service 1") Then
EventLog.Create EventSource("Se rvice1", "Applicatio n")
End If

EventLog1.Sourc e = "Service1"
EventLog1.Write Entry("This is a simple event log entry")

End Sub

Needless to say, there are no EventLog entries occurring. I've also tried
to attach to the process but again, it doesn't seem to fire.

Any direction would be greatly appreciated.

Thanks!
Rick


Mar 16 '07 #1
2 5808
"Rico" <me@you.comschr ieb:
I'm trying run a process at regular intervals using a windows service.
the problem is, the timer_tick event doesn't appear to be working. I've
written the following code as a test;

Public Class FileName
Protected Overrides Sub OnStart(ByVal args() As String)

Timer1.Interval = 1000
Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Note that 'System.Windows .Forms.Timer' does not work if its not placed on a
form. You may want to use 'System.Timers. Timer' or 'System.Theadin g.Timer'
instead.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 16 '07 #2
Excellent! That was the ticket!

Thanks Herfried!

Rick

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atwrote in message
news:uq******** ******@TK2MSFTN GP04.phx.gbl...
"Rico" <me@you.comschr ieb:
>I'm trying run a process at regular intervals using a windows service.
the problem is, the timer_tick event doesn't appear to be working. I've
written the following code as a test;

Public Class FileName
Protected Overrides Sub OnStart(ByVal args() As String)

Timer1.Interva l = 1000
Timer1.Enabl ed = True

End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventAr gs) Handles Timer1.Tick

Note that 'System.Windows .Forms.Timer' does not work if its not placed on
a form. You may want to use 'System.Timers. Timer' or
'System.Theadin g.Timer' instead.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
33586
by: J. Hill | last post by:
I have a Windows Service with a timer but the .Tick event is not being fired/called. Don't know what code to include...I enabled and started the timer...I have the exact same code in a Windows form and it works fine, but in the service: nothing. .... this.components = new System.ComponentModel.Container(); this.tmrTimer = new System.Windows.Forms.Timer(this.components); // // tmrTimer //
8
2784
by: Daniel P. | last post by:
I'm trying to set a timer that gets called every 3 seconds so I can update a field in the UI with the time elapsed since the process started. What am I doing wrong that timerDF_Tick does not get called? private System.Windows.Forms.Timer timerDF; this.timerDF = new System.Windows.Forms.Timer(this.components);
7
2383
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly reset I put some extra code in the subs that enable and disable the timer. They fire as expected. To test this I added a second timer with a 1 second interval. The event for this time would output the enabled status of the first timer and its...
10
1836
by: Bob | last post by:
I have a splashscreen running on a thread from Sub Main and it works OK. It displays information in a statusbar about queries. I also have a time on the splashscreen, but the tick event never gets fired. In the Load Event if the splashscreen I call the timer's Start() event. HOw do I get the tick event to fire?
1
3956
by: Manuel | last post by:
Used VS2005 to create a windows service and I can't make a timer trigger the tick/elapsed event. On the form viewer I dragged a timer from the components section of the toolbar, enabled it but the tick event does not fire! I tried this other method but the elapsed event does not fire. ---------- Private WithEvents MyTmr As New System.Timers.Timer(1000) Private Sub MyTmr_Elapsed(ByVal sender As Object, ByVal e As
2
2214
by: cntams | last post by:
All, I have a Windows Service and it has one System.Timers.Timer that fires every 500 milliseconds. Now I have noticed that there's a bug in System.Timers.Timer when it's being used combined with Windows Service. That is, the Timer won't fire again once it's stopped (Timer.Stop() or Timer.Enabled = False) (http://support.microsoft.com/kb/842793/en-us). Instead of using Threading.Timer, can I just have the code to run inside the...
9
2645
by: archana | last post by:
Hi all, I want to know about interval of timer. I am using timer in windows service.I head somewhere that when i set interval property of timer while setting interval, restart time of Pc is consider. My question is if i am using timer in my windows service, is there any place where interval related information like interval set used by my
8
6864
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have never used this timer. I used the documentation from Microsoft as a guide, but I cannot get this timer to work. Protected Overrides Sub OnStart(ByVal args() As String) Dim myTimer As New TimerState()
3
3883
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI Thread)? In some of the timers I update some UI controls e.g statusbar.labels and I
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.