By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,905 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,905 IT Pros & Developers. It's quick & easy.

Timer Tick Event not Working in Windows Service

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
Dear hill

i am also facing the same problem.

can u plz help me to sort it out
Feb 16 '07 #5

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.