Reputation: 788
can any one please check what i am doing onstart is correct or not please. i am getting error service started and stopped automatically. i want to run my service every 10 minutes. please help its been 4 hours i am struggling
protected override void OnStart(string[] args)
{
try
{
_aTimer.Start();
_aTimer.Enabled = true;
_aTimer = new System.Timers.Timer(10 * 60 * 1000);//10 minutes
_aTimer.AutoReset = true;
_aTimer.Elapsed += new System.Timers.ElapsedEventHandler(_aTimer_Elapsed);
}
catch(Exception ex) {
RMLogger.RMException("ServiceManager", this.GetType().Name.ToString(), ex.ToString());
}
}
Upvotes: 1
Views: 6747
Reputation: 8462
Make sure you have the same .net framework version you are compiling to to the server you are installing the windows service
I had the same issue, I was compiling it in 4.5.2 and the server 4.5. The installutil tricks us allowing it to be installed but it doesn't start.
Upvotes: 2
Reputation: 1
For what I see what goes wrong here is the following:
I think that the timer automatically resets at the new given instance.
Try give it a new instance first and the required parameters to run the timer. Then start the timer.
Upvotes: 0
Reputation: 1187
I think you have things a little confused here. You say
i want to run my service every 10 minutes.
but the timer that you are starting will run every 10 minutes only while the service is continually running.
Either you mean what you way and want to start the service every 10 minutes, in which case I would use something like Task Scheduler to start the service every 10 minutes, let it do it's processing, and then shut down again.
Or you just let your service run continually and the timer event will fire every 10 minutes.
Upvotes: 0