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 BIGService
is an Abstract class, that has 5 descendants (5 individual service classes with this common parent). 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 ExecutedToday
property and void SetAsExecuted
method.
My question is: where do you recommend I should call the SetAsExecuted
method? Which way is more subservient? In the end of the Execute()
method itself or in my copied code at the end of the if
clause?
(Similar situations have happened to me several times, I just now have the time to ask other's opinion)