Click here to Skip to main content
15,909,503 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi Dear All,
Can anyone please explain me about Using System.Timers.Timer in Windows service..?
I want to know the use and benefits of the "namespace" System.Timers..
Plz give some examples if possible

Regards,
Raj
Posted
Updated 22-Mar-11 19:43pm
v2
Comments
Wendelius 23-Mar-11 1:43am    
Pre tags removed
Raj.rcr 23-Mar-11 2:05am    
well done Mika
RaviRanjanKr 29-Nov-11 2:56am    
A suggestion :- Its not a good practice to use short text words like 'Plz' instead of Please.so please avoid it.

1 solution

There is nothing to explain. Benefits… compared to what?
Read help and use it. I don't see where you can face any problem, but when you do, ask another Question.

My question is: why using a timer at all? Usually, using threads is much more robust and easy. Considering the fact, that Windows Service will require creation of threads anyway, why not using an extra thread (possible with System.Threading.Thread.Sleep for timing). The general recommendation is: if you have any opportunity to avoid using any timers, use it.

—SA
 
Share this answer
 
Comments
Raj.rcr 23-Mar-11 2:09am    
Hi, I am given a task to understand about this, to use it in one of the modules in a project. I searched in google, but didnt understand clearly. So posted here to get better idea.. But, in one of the sites, I saw like System.Timers.Timer is ideal for windows service rather than System.Threading.Thread... So, I am still confused.
Sergey Alexandrovich Kryukov 23-Mar-11 2:17am    
Who cares what some site writes? It really depends on application. Think how tricky is using a timer: what happens if your did not finish to process timer event when a next event happens? With thread, all execution will go a bit slower, but not disasters. If you simply need to poll some data from time to time, thread is much better, but if you need very accurate timing of periodic signal, you may need a timer. But when in service you may need it. There is not video or audio, nothing is real time... Think about it.
--SA
Wendelius 23-Mar-11 3:07am    
Good answer in whole, 5.
Sergey Alexandrovich Kryukov 23-Mar-11 14:49pm    
Thank you, Mika.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900