Timer not working in .net

A

archana

Hi all

I am having application which is using server based timer that is timer

from namespace system.timer.

I am having windows service which i want to run after every 1 hour and
after every one hour i am sending mail.

In service.cs class i am creating one worker thread and in thread
procedure i am enabling one timer after thread procedure is completed
and in timer's elapsed event i am calling function of sending mail.

But even if i set interval as1 hours my code is sometime running
continuously means sending mail after 1 min only instead of after 1
hour which is increasing my mail box size.

Can some one tell me why thisis happening. Or can't i start timer in
thread procedure at the end of thread procedure.

Am i doing something wrong?

thanks in advance,
 
W

William Stacey [MVP]

Can you post some code. I prefer the System.Threading.Timer timer myself.

--
William Stacey [MVP]

| Hi all
|
| I am having application which is using server based timer that is timer
|
| from namespace system.timer.
|
| I am having windows service which i want to run after every 1 hour and
| after every one hour i am sending mail.
|
| In service.cs class i am creating one worker thread and in thread
| procedure i am enabling one timer after thread procedure is completed
| and in timer's elapsed event i am calling function of sending mail.
|
| But even if i set interval as1 hours my code is sometime running
| continuously means sending mail after 1 min only instead of after 1
| hour which is increasing my mail box size.
|
| Can some one tell me why thisis happening. Or can't i start timer in
| thread procedure at the end of thread procedure.
|
| Am i doing something wrong?
|
| thanks in advance,
|
 
G

Guest

If this thing needs to "Rip Van Winkle" for a full hour before it ever wakes
up and does something, I think you'd be better served by just writing it as a
console app and having Task Scheduler call it once an hour. No need to have
the overhead of a service just to have it wake up and do something once per
hour.
Peter
 
A

archana

Hi,

thanks to ur reply.

but i want to know reason behind this as currently i am using timer in
all my application.

So changing it to console application will create some overheads for
me.

So please tell me why this is happening. I am not doing any heavy
processing which will require more than hour.

If u have any idea please help me.

thanks in advance.
 
G

Guest

Archana,
converting your app to a console app that gets run on a scheduled basis by
Task Scheduler should reduce, not increase the overhead, since a timer would
no longer be necessary. Your app would simply do its thing in its Main( )
method each time it is run and then quit. No service overhead, and only a
minimal memory footprint for a short period of time whenever it is run.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top