I have the following code:
static void TimerElapsed(object sender, ElapsedEventArgs e)
{
foreach (BIGService bigService in runningServices)
{
if (!bigService.ExecutedToday)
{
int executionResult = bigService.Execute();
string serviceName = bigService.ToString();
if (executionResult == 0)
{
EventLogger.WriteToEventLog("Success");
}
else
{
EventLogger.WriteToEventLog("Failure");
}
}
}
}
where BIGServiceBIGService
is an Abstract class, that has 5 descendants (5 individual service classes with this common parent).
The The enclosing timer's interval is 7200. So it elapses in every 2 hours.
All services must be run only once a day. Therefore I created a bool ExecutedTodaybool ExecutedToday
property and void SetAsExecutedvoid SetAsExecuted
method.
My question is what: where do you recommend, where should I should call the SetAsExecutedSetAsExecuted
method? Which way is more subservient?
In In the end of the Execute()Execute()
method itself or in my copied code inat the end of the ifif
clause?
(Similar situations have happened to me several times, I just now have the time to ask other's opinion)
Thank you in advance!