问题:在长时间运行过程中跟踪三种状态。 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;
}
}
监听器为正在运行的进程设置适当的变量......我实际上做了什么工作。只是想知道是否有更好的方法来做到这一点。