ToString1
asked on
set timer in windows service
I'm building a c# windows service I would like some code to call a method periodically say every, hour or every 24 hours (which can be amended from app.config)
I would like code snippet for this and be able to get config values from app.config
I would like code snippet for this and be able to get config values from app.config
ASKER
I am calling the a method that is outside of the windows service and already have a reference to that. The windows service would start automatically I think but am unsure.
Also writing to an event log would be good.
Also writing to an event log would be good.
the method can be run stabdalone from a scheduler which uses the data from its app.config
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok thanks
So in my windows service project (visual studio) I have a file called program.cs
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new TestService()
};
ServiceBase.Run(ServicesTo Run);
}
I want to leave this file alone and just use TestService so where would I put the code
So in my windows service project (visual studio) I have a file called program.cs
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new TestService()
};
ServiceBase.Run(ServicesTo
}
I want to leave this file alone and just use TestService so where would I put the code
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK thanks but I am instantiating
System.Timers.Timer
but I don't get the tick property, I would like to use the Elapsed property
System.Timers.Timer
but I don't get the tick property, I would like to use the Elapsed property
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant thanks very much
One last thing in app.config, say I want to set intervals for 1 hour, 2 hour ,3 hour upto daily
Thanks!
One last thing in app.config, say I want to set intervals for 1 hour, 2 hour ,3 hour upto daily
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>One last thing in app.config, say I want to set intervals for 1 hour, 2 hour ,3 hour upto daily
is you mean every 1 hour then:
</configuration>
<appSettings>
<add key="TimeInterval" value="01:00:00" />
</appSettings>
</configuration>
is you mean every 1 hour then:
</configuration>
<appSettings>
<add key="TimeInterval" value="01:00:00" />
</appSettings>
</configuration>
ASKER
OK what about daily
daily is every 24 hrs so:
</configuration>
<appSettings>
<add key="TimeInterval" value="24.00:00:00" />
</appSettings>
</configuration>
</configuration>
<appSettings>
<add key="TimeInterval" value="24.00:00:00" />
</appSettings>
</configuration>
is the windows service meant to run manually or auto?