Skip to main content
Post Closed as "Not suitable for this site" by RubberDuck, Quill, Mast, user62850, IEatBagels
deleted 20 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

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!

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 what do you recommend, where should I call the SetAsExecuted method? Which way is more subservient?

In the end of the Execute() method itself or in my copied code in 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)

Thank you in advance!

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)

Source Link

How should I set a daily method as executed, from inside or from outside?

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 what do you recommend, where should I call the SetAsExecuted method? Which way is more subservient?

In the end of the Execute() method itself or in my copied code in 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)

Thank you in advance!