473,729 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer Tick Event not Working in Windows Service

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.Componen tModel.Containe r();
this.tmrTimer = new System.Windows. Forms.Timer(thi s.components);
//
// tmrTimer
//
this.tmrTimer.I nterval = 6;
this.tmrTimer.T ick += new System.EventHan dler(this.tmrTi mer_Tick);

....

//In OnStart or Initialization -- tried both...
tmrTimer.Start( );
tmrTimer.Enable d = true;
/*
also tried
tmrTimer.Enable d = true;
tmrTimer.Start( );
*/
....
private void tmrTimer_Tick(o bject sender, System.EventArg s e) {
tCurrTime = DateTime.Now;
EventLog.WriteE ntry("Timer Tick", "We have ticked...",
EventLogEntryTy pe.Error);

if (tCurrTime.Hour == 0){
DoMidNightServi ce();
}


Even a "did you check this" would be a great help.

Thanks,
J.
Nov 16 '05 #1
7 33584
Use either the Timer class from either System.Threadin g or System.Timers
instead.

Ken
"J. Hill" <J. Hi**@discussion s.microsoft.com> wrote in message
news:C7******** *************** ***********@mic rosoft.com...
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.Componen tModel.Containe r();
this.tmrTimer = new System.Windows. Forms.Timer(thi s.components);
//
// tmrTimer
//
this.tmrTimer.I nterval = 6;
this.tmrTimer.T ick += new System.EventHan dler(this.tmrTi mer_Tick);

...

//In OnStart or Initialization -- tried both...
tmrTimer.Start( );
tmrTimer.Enable d = true;
/*
also tried
tmrTimer.Enable d = true;
tmrTimer.Start( );
*/
...
private void tmrTimer_Tick(o bject sender, System.EventArg s e) {
tCurrTime = DateTime.Now;
EventLog.WriteE ntry("Timer Tick", "We have ticked...",
EventLogEntryTy pe.Error);

if (tCurrTime.Hour == 0){
DoMidNightServi ce();
}


Even a "did you check this" would be a great help.

Thanks,
J.

Nov 16 '05 #2
J.
In addition to the other comments.

In addition to the others comments, the following articles in MSDN Magazine
explain the difference between the three timer objects in .NET & when to use
each.

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

http://msdn.microsoft.com/msdnmag/is...3/default.aspx

The above articles also discusses if & how each timer interacts with
threading.

I'm using System.Timers.T imer (instead of System.Threadin g.Timer) in my
Windows Service, as I don't really need the extra features of
System.Threadin g.Timer. Either should work in your case.

Hope this helps
Jay
"J. Hill" <J. Hi**@discussion s.microsoft.com> wrote in message
news:C7******** *************** ***********@mic rosoft.com...
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.Componen tModel.Containe r();
this.tmrTimer = new System.Windows. Forms.Timer(thi s.components);
//
// tmrTimer
//
this.tmrTimer.I nterval = 6;
this.tmrTimer.T ick += new System.EventHan dler(this.tmrTi mer_Tick);

...

//In OnStart or Initialization -- tried both...
tmrTimer.Start( );
tmrTimer.Enable d = true;
/*
also tried
tmrTimer.Enable d = true;
tmrTimer.Start( );
*/
...
private void tmrTimer_Tick(o bject sender, System.EventArg s e) {
tCurrTime = DateTime.Now;
EventLog.WriteE ntry("Timer Tick", "We have ticked...",
EventLogEntryTy pe.Error);

if (tCurrTime.Hour == 0){
DoMidNightServi ce();
}


Even a "did you check this" would be a great help.

Thanks,
J.

Nov 16 '05 #3
J. Hill wrote:
EXCELLENT!!!
I had just 'migrated' my code from my development Windows app and brought the timer code over. As soon as I created a 'new' timer of System.Timers.T imer it worked perfectly.

Thanks a ton!!!

I do have another question, do I mark this thread "answered" so in case anyone else is as boneheaded as me, they will be able to know the solution is here?

This is Usenet.

Not RAID.

"Jay B. Harlow [MVP - Outlook]" wrote:

J.
In addition to the other comments.

In addition to the others comments, the following articles in MSDN Magazine
explain the difference between the three timer objects in .NET & when to use
each.

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

http://msdn.microsoft.com/msdnmag/is...3/default.aspx

The above articles also discusses if & how each timer interacts with
threading.

I'm using System.Timers.T imer (instead of System.Threadin g.Timer) in my
Windows Service, as I don't really need the extra features of
System.Thread ing.Timer. Either should work in your case.

Hope this helps
Jay
"J. Hill" <J. Hi**@discussion s.microsoft.com> wrote in message
news:C7****** *************** *************@m icrosoft.com...
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.compone nts = new System.Componen tModel.Containe r();
this.tmrTime r = new System.Windows. Forms.Timer(thi s.components);
//
// tmrTimer
//
this.tmrTime r.Interval = 6;
this.tmrTime r.Tick += new System.EventHan dler(this.tmrTi mer_Tick);

...

//In OnStart or Initialization -- tried both...
tmrTimer.Sta rt();
tmrTimer.Ena bled = true;
/*
also tried
tmrTimer.Ena bled = true;
tmrTimer.Sta rt();
*/
...
private void tmrTimer_Tick(o bject sender, System.EventArg s e) {
tCurrTime = DateTime.Now;
EventLog.Wri teEntry("Timer Tick", "We have ticked...",
EventLogEntr yType.Error);

if (tCurrTime.Hour == 0){
DoMidNightSe rvice();
}


Even a "did you check this" would be a great help.

Thanks,
J.


Nov 16 '05 #4
Dear hill

i am also facing the same problem.

can u plz help me to sort it out
Feb 16 '07 #5
I use System.Timers.T imer in all my service programs and they work fine.
The Timer.Elapsed event will get thru regulary.

"William" <Wi*****@discus sions.microsoft .comha scritto nel messaggio
news:DC******** *************** ***********@mic rosoft.com...
Dear hill

i am also facing the same problem.

can u plz help me to sort it out


Feb 16 '07 #6
Can you send me that example only for the timer
its urgnt
Thank you

"Laura T." wrote:
I use System.Timers.T imer in all my service programs and they work fine.
The Timer.Elapsed event will get thru regulary.

"William" <Wi*****@discus sions.microsoft .comha scritto nel messaggio
news:DC******** *************** ***********@mic rosoft.com...
Dear hill

i am also facing the same problem.

can u plz help me to sort it out


Feb 17 '07 #7
I have written a function in my windows service. on my service starts the
timer is started and after some interval i stopped the timer and calling my
function. but my function is not working.

can any one tell me how to call my function in an interval of period.

i want the timer should start first and some interval of time the timers
wants to stop at that time my function should execute. after my function
excution the timer should start. again some interval the timer wants to stop
and my function should execute.

can any one help me.

Regards
William
"Laura T." wrote:
I use System.Timers.T imer in all my service programs and they work fine.
The Timer.Elapsed event will get thru regulary.

"William" <Wi*****@discus sions.microsoft .comha scritto nel messaggio
news:DC******** *************** ***********@mic rosoft.com...
Dear hill

i am also facing the same problem.

can u plz help me to sort it out


Feb 17 '07 #8

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

Similar topics

2
2083
by: Rajesh Abraham | last post by:
I have a timer in my Windows Service project and I am trying to do some processing on the tick event of the timer but this event does not seesms to be raised. Below is some code segment. Any Idea? Thanks, Rajesh Abraham -----Code Below------
1
3955
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
10
2247
by: janhm | last post by:
Hello. I have created a windows service that is supposed to turn the monitor on/off at specific times a day, but my timer dosn't seem to work. on my Service Start i set : timer1.Enabled = true; timer1.Interval = 1500;
5
12243
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
8
6860
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()
2
1418
by: dhulapati | last post by:
I cant get the timer working with the windows service. I have the timer set to 3600 ms. It polls only for Start and Stop but not at intervals. The timer1.tick event handler is called at the initializecomponent() OnStart () enables the timer1 and OnStop() disables the timer1. Can anybody help?
2
5803
by: Rico | last post by:
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)
11
2599
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn library as I thought this would be a good start!!!) but nothing happens :- Imports System.Timers
3
3880
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
8761
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
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
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
6722
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
6022
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
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.