M
mamin
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,currentDate.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?
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,currentDate.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?