Dear All,
I have windows service done with C# and able to be install using the installutil.exe. My problem now is that I want to set it like to run on particular time of day for instance 10.00 am daily How can I set this I have tried to use timer but it sets an interval only Another thing is that I have debug.write() in my windows service where can i check the output of the debug.write Where is the file Thanks.

windows service running on particular time and debug.write() where it prints ?
RockyMountainer
Well this is question about windows service lyfecycle :)
For more info take a look at ServiceBase class.
Window service performs operations on two basis:
Which one you get depends only on your goals (which I still do not know so I cannot give advise)
Hope this helps.
sureshsundar007
1. About running service on particular time of day you have two options:
2. Debug.MethodNAme works only if assembly is compiled in Debug configuration. Consider using Trace Class with TextWriterTraceListener Class (System.Diagnostics)
Hope this helps
DeltaOps101
Dear Galin,
I read in some site in the net saying that thread timer is more secure than timer So what is this type of timer is it different than the one you suggesting to me Thanks.
ralfkret
Dear Gallin,
1. Which you think is better I think a pair of schedule task will be good one for start and stop the service Do you have any example code how to start and stop the service plsease. Any example on the code against time also will be valuable to me.
2. Ok about the debug.write infact in my windows service I put a line. Now I am wondering where will the output of the debug.write can be seen Thanks for your help.
Shihan
Dear Galin,
Thanks the website was very informative on service class. But to be frank I am very new and I saw even the c# example code attached together in the web site. I also understand that in my case the operation is on iterative basis. So basically the main engine which suppose to run it should be located in the onStart function am i right I saw the code and trying to understand and implement for my program. What is the worker thread I want to run my service between a range of time at a particular interval If you have any other reference please do help me. Thanks.
Jonathan Allen
1. I prefer detecting in code if it is appropriate time to perform actions. thus way you eliminate chance to have service stopped at the time it must work.
in your code you can check if it is appropriate time with similar code
//code inside if statement is executed only beteween 10 AM and 6 PM
//get now
DateTime now = DateTime.Now;
if (10 <= now.Hour && now.Hour <= 18){
//your code here executed every day beteween 10 AM and 6 PM
}
2. Debug and Trace classes write in all listeners
hope this helps
zhuyanjun
Dear Galin,
I got your idea. The problem now I need to confirm with you is that am i writing my action codes in the write place or not When I create a new windows service program with VS2005 I get only 2 function OnStart and OnStop. So I am putting my code in the OnStart. So it this correct to do that or not Actually once I have installed and started the service it gets start to it will call the OnStart function rite So after that where does it go
hte
to be honest I haven't dug deeper into these timers business and I cannot adivse you.
Take a look at these articles. I hope you will find the answer:
Hope this helps
UPDATE: I looked at Reflector and System.Timers.Timer acts as wrapper arround System.Threading.Timer
Boy from Turkey
as I understand you have to.
See the code below:
public
partial class Service1 : ServiceBase{
Timer timer = null; public Service1(){
InitializeComponent();
} protected override void OnStart(string[] args){
timer = new Timer();
timer.Interval = 2000; //two seconds
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Enabled = true;
} void timer_Elapsed(object sender, ElapsedEventArgs e){
//get now
DateTime now = DateTime.Now;
if (10 <= now.Hour && now.Hour <= 18){
//your code here
}
} protected override void OnPause(){
base.OnPause();
timer.Enabled = false;
} protected override void OnContinue(){
base.OnContinue();
timer.Enabled = true;
} protected override void OnStop(){
timer.Enabled = false;
timer.Dispose();
}
}
Hope this helps