Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute at certain time. 1

Status
Not open for further replies.

robertfah

Programmer
Mar 20, 2006
380
US
I've got a program that is on a timer and constantly runs throughout the day. It can run from every 3 seconds to every 5 minutes (or anything in between) because the program let's the choose the rate at which the program executes.

I need a way to determine if the program has ran between 8:00am and 8:06am and send an email if so (I know how to send the email part). Can anyone tell me how I can do this?
 
there are a number of ways to do this. the "best" solution will depend on how you are currently executing the task, how you tell the task to execute, if you can change, or introduce new code, to any of this existing code.

ultimately what you will need is an object to represent that the task was executed. usually this would include (who [user name], when [date and time], where [machine name/ip], etc). you can then pass this information along (send an email, persist to a database, queue a service bus, etc.)

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Thanks for the response. My app. is not that important (LOL) for all that stuff. It's a simple app that executes (based on a timer) every 5 minutes (again, which can be set by the user between 1 and 300 seconds, which essentially sets the timer interval). We're having some difficulty determining if the program is running all day or not. So instead of watching it, I was going to put some code in that said something like:
Code:
If (DateTime.Now.ToString() Is between 8:00am and 8:06am)
  Send me an email
Else
  Do nothing.

This way I would get an email each morning to tell if the program ran. If it dies at 3pm, then I won't get the next mornings email and know somethings up. I don't need to know when it died or anything else, just that it stopped running.
 
to validate the time
Code:
var eight = new DateTime.Today.AddHours(8);
var nine = new DateTime.Today.AddHours(9);
var now = DateTime.Now;

if(now >= eight && now < nine)
{
   send an email
}
This seems like a hack. As I said before the system and/or operation architecture will help determine the optimal solution.

typically a timed event is part of a windows service (not a desktop/web application). a UI can control when the service starts and stops (if necessary), but the service itself shouldn't require a user to be logged on or have an application running.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Why not keep a log file somewhere and just write to that when it runs? If you only want to capture it during a certain time, you can check the time when it fires and only write it if it's in that time... or have it touch a file each time it runs so that the datetime stamp changes.
 
This seems like a hack. As I said before the system and/or operation architecture will help determine the optimal solution.

typically a timed event is part of a windows service (not a desktop/web application). a UI can control when the service starts and stops (if necessary), but the service itself shouldn't require a user to be logged on or have an application running.

Thank you for your input, it's appreciated and not overlooked. However, I am in a situation that I cannot change the current implementation and am forced to work with what I have.

Why not keep a log file somewhere and just write to that when it runs? If you only want to capture it during a certain time, you can check the time when it fires and only write it if it's in that time... or have it touch a file each time it runs so that the datetime stamp changes.
We could do this but if the program runs for 5 days and stops, the log file has the potential of having thousands of records to wade through (especially if the user decides to run the program every 10 seconds, which is done quite often).
 
We could do this but if the program runs for 5 days and stops, the log file has the potential of having thousands of records to wade through
there are tools to query log files.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
You can also use a "tail" utility to only check the last few lines.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top