mamin,
Don't use a windows service for this. Write your app as an executable
and then set it up as a scheduled task which runs at 11 PM. If you need to
change the time, then just change the scheduled task.
The problem with setting it up as a service is that the config file is
read once. Even if you change the time, the app won't know. .NET 2.0 has
new options in the config classes to reload the file, but then you have to
ask yourself, how often will you refresh the app config file?
It's a lot of extra processing for something that runs once a day. Just
set it up as a scheduled task.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"mamin" <ma**************@vp.pl> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
I need to write application, which checks the time and executes some
method when the current time is 11pm.Moreover, I need to keep the time
parameter in App.config file. My question is, how to do it ellegant?
Now, my sourcecode looks as follows:
App.Config file:
<add key="ProcessKillingTime" value="23"></add>
Application.cs file:
while(1)
{
DateTime currentDate=System.DateTime.Now;
DateTime processKillingTime=new
DateTim(currentDate.Year,currentDate.Month,current Date.Day,
processKillingTime,0,0);
if( processKillingTime.AddMinutes(30) > currentDate
&& processKillingTime.AddMinutes(-30) < currentDate)
{ code that should be executed at 23pm}
...here,waits 1 hour.
}
So, as you can see it's not very elegant. Any idea to do it better?