473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Application executed at given time

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?

May 22 '06 #1
5 1092
"mamin" <ma**************@vp.pl> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
So, as you can see it's not very elegant. Any idea to do it better?


Sounds like an ideal solution for a Windows service...
May 22 '06 #2
Well, in fact it is windows service. But the code I need to improve is:
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) {}
Don't you think that better way to do it exists?

May 22 '06 #3
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?

May 22 '06 #4
"mamin" <ma**************@vp.pl> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
Don't you think that better way to do it exists?


Actually, Nicholas Paladino's suggestion is much better...
May 22 '06 #5
Yeah, I think so.

May 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: picard | last post by:
I have seen in various posts that there are tricks to increasing the largest continuous memory block available to an application on a windows machine. I want to prove this is possible using a...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
6
by: sumedh..... | last post by:
main() { int i; fork(); fork(); fork(); printf("----"); } how many times the printf will be executed .
7
by: Cramer | last post by:
In addition to Web.config, I have a few configuration values that I store in a sql server database. I would like to read them from the database only once per Application.Start (there is no need to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.