0

问题:在长时间运行过程中跟踪三个状态。1) 是 EOD(一天结束)信号,用于发送给定日期收到的电子邮件报告 2) 在同一天收到的新信号,用于发送修订报告(增加修订号 3)是在发送时收到的信号发生,如果是这样,只需警告用户正在处理 EOD 信号。

收到一天结束信号后,在实际一天结束时……午夜,所有变量都被重置

目前正在使用三个单独的布尔值处理。问题是,是否有一种更有效的方法可以在不使用这么多布尔变量的情况下在这个无限循环中跟踪这三个条件。

一些代码因为发布它太多了,但这里是 jist:

public class job
{
    private bool receivedEndOfDaySignal = false;
    private bool receivedEodOfDaySignalSend = false;
    private bool receivedEodOfDaySignalDuringSend = false;

    public void RunThisJob(IJobData JobData, IJobStatus Status)
    {
         // job setup code.
         // listener for incoming signals
         Helper.OnSignalReceived += Helper_OnSignalReceived;



         // loop for constant run
           for (; ; )
            {
                //We're still cooking
                Helper.StillGoing();

                //wait till the email send is supposed to execute
                Helper.WaitUntilTime(RunTime);

                //Send the mail
                SendMail();

                // reset signal booleans
                receivedEodOfDaySignalSend = receivedEodOfDaySignalDuringSend = false;

    }

    bool Helper_OnSignalReceived(IJobSignal signal, BatchWaitType waitType)
    {
        //Which?
        switch (signal.Code.ToUpper())
        {
            case "ENDOFDAY":
                // Acknowledge the end of day signal 
                // if end of day received more than once before being reset.
                if (receivedEodOfDaySignalDuringSend)
                {
                    Helper.Logger.Log(LogStatus.Info, "Batch", "An END OF DAY signal was already received. ");
                    Helper.Status.AcknowledgeSignal(signal);
                    return true;
                }
                // when an eod signal is received and revision count has been initialized increase the count.
                // only initialized after first eod signal received and not when another receiving during a send
                if (revisionCount != null) revisionCount++;
                // set all the flags when EOD comes through even though some will still be set
                receivedEndOfDaySignal = receivedEodOfDaySignalSend = receivedEodOfDaySignalDuringSend = true;
                Helper.Status.AcknowledgeSignal(signal);
                return true;
        }

        //Still here?
        return false;
    }

}

侦听器为正在运行的进程设置适当的变量......我所拥有的实际上是有效的。只是想知道是否有更好的方法来做到这一点。

4

0 回答 0