473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.ComponentModel.Container();
this.tmrTimer = new System.Windows.Forms.Timer(this.components);
//
// tmrTimer
//
this.tmrTimer.Interval = 6;
this.tmrTimer.Tick += new System.EventHandler(this.tmrTimer_Tick);

....

//In OnStart or Initialization -- tried both...
tmrTimer.Start();
tmrTimer.Enabled = true;
/*
also tried
tmrTimer.Enabled = true;
tmrTimer.Start();
*/
....
private void tmrTimer_Tick(object sender, System.EventArgs e) {
tCurrTime = DateTime.Now;
EventLog.WriteEntry("Timer Tick", "We have ticked...",
EventLogEntryType.Error);

if (tCurrTime.Hour == 0){
DoMidNightService();
}


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

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

Ken
"J. Hill" <J. Hi**@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.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.ComponentModel.Container();
this.tmrTimer = new System.Windows.Forms.Timer(this.components);
//
// tmrTimer
//
this.tmrTimer.Interval = 6;
this.tmrTimer.Tick += new System.EventHandler(this.tmrTimer_Tick);

...

//In OnStart or Initialization -- tried both...
tmrTimer.Start();
tmrTimer.Enabled = true;
/*
also tried
tmrTimer.Enabled = true;
tmrTimer.Start();
*/
...
private void tmrTimer_Tick(object sender, System.EventArgs e) {
tCurrTime = DateTime.Now;
EventLog.WriteEntry("Timer Tick", "We have ticked...",
EventLogEntryType.Error);

if (tCurrTime.Hour == 0){
DoMidNightService();
}


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.Timer (instead of System.Threading.Timer) in my
Windows Service, as I don't really need the extra features of
System.Threading.Timer. Either should work in your case.

Hope this helps
Jay
"J. Hill" <J. Hi**@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.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.ComponentModel.Container();
this.tmrTimer = new System.Windows.Forms.Timer(this.components);
//
// tmrTimer
//
this.tmrTimer.Interval = 6;
this.tmrTimer.Tick += new System.EventHandler(this.tmrTimer_Tick);

...

//In OnStart or Initialization -- tried both...
tmrTimer.Start();
tmrTimer.Enabled = true;
/*
also tried
tmrTimer.Enabled = true;
tmrTimer.Start();
*/
...
private void tmrTimer_Tick(object sender, System.EventArgs e) {
tCurrTime = DateTime.Now;
EventLog.WriteEntry("Timer Tick", "We have ticked...",
EventLogEntryType.Error);

if (tCurrTime.Hour == 0){
DoMidNightService();
}


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.Timer 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.Timer (instead of System.Threading.Timer) in my
Windows Service, as I don't really need the extra features of
System.Threading.Timer. Either should work in your case.

Hope this helps
Jay
"J. Hill" <J. Hi**@discussions.microsoft.com> wrote in message
news:C7**********************************@micros oft.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.ComponentModel.Container();
this.tmrTimer = new System.Windows.Forms.Timer(this.components);
//
// tmrTimer
//
this.tmrTimer.Interval = 6;
this.tmrTimer.Tick += new System.EventHandler(this.tmrTimer_Tick);

...

//In OnStart or Initialization -- tried both...
tmrTimer.Start();
tmrTimer.Enabled = true;
/*
also tried
tmrTimer.Enabled = true;
tmrTimer.Start();
*/
...
private void tmrTimer_Tick(object sender, System.EventArgs e) {
tCurrTime = DateTime.Now;
EventLog.WriteEntry("Timer Tick", "We have ticked...",
EventLogEntryType.Error);

if (tCurrTime.Hour == 0){
DoMidNightService();
}


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.Timer in all my service programs and they work fine.
The Timer.Elapsed event will get thru regulary.

"William" <Wi*****@discussions.microsoft.comha scritto nel messaggio
news:DC**********************************@microsof t.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.Timer in all my service programs and they work fine.
The Timer.Elapsed event will get thru regulary.

"William" <Wi*****@discussions.microsoft.comha scritto nel messaggio
news:DC**********************************@microsof t.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.Timer in all my service programs and they work fine.
The Timer.Elapsed event will get thru regulary.

"William" <Wi*****@discussions.microsoft.comha scritto nel messaggio
news:DC**********************************@microsof t.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
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?...
1
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...
10
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 =...
5
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...
8
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...
2
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...
2
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; ...
11
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.