枚举和标志在给定的环境条件下进行检查

时间:2010-08-06 12:43:27

标签: c# enums flags

我有一个事件ServerStateReceived在这里检查4台服务器的状态,无论它们是UP还是Down。在这种特定类型的场景服务器将开始停机,但有些时候服务器应该是Up。所以所有4台服务器down和ReadySent = true;我们需要寻找一个罕见的案例。 我有一个方法public write()在这个方法中我需要一个逻辑来检查条件,如果标志ReadySent = true;并且在ServerStateReceived事件中所有服务器都处于DOWN状态,如果满意的控制应该转到事件ServerStateReceived。如果我在这里等了一段时间所有4台服务器都会在那个时候UP,只有控件会来自ServerStateReceived事件来写(),我不想用 sleep()方法或挂起等等,我需要一个逻辑这里通过代码

这是不是c#code

的算法
Write()
{
If(ReadySent = true && all servers  in the event EventHandler ServerStateReceived DOWN) 
Go to 
              public event EventHandler ServerStateReceived
              {
here checks going on 
if(all servers UP)
go to write() method
}
}

这是我需要实现上述逻辑的c#代码

Public write()
{
// here need the logic to move control to event ServerStateReceived if both flag ReadySent = true; and all servers DOWN stay there for some time without using sleep() once they all UP program control will come to write() method
}

private enum StateType : int
              {
                 Initial = 0,
                 Up = 1,
                 Down = 2
              }
              public event EventHandler ServerStateReceived
              {
              add
                 {
                    m_events.AddHandler(ServerStateEvent, value);
                                if (m_alarmServerUp == StateType.Up)
                    {
                       value(this,
                          new ServerStateEventArgs(ServerComponentType.AlarmServer, true));
                    }
                    else
                    {
                       value(this,
                          new ServerStateEventArgs(ServerComponentType.AlarmServer, false));
                    }
                   .
                   .
                   .

    // **like this 3 more conditions checking are going on(total 4)**

1 个答案:

答案 0 :(得分:0)

Public Write()
{
   System.Threading.Thread.Sleep(20000);
}

这样可行但我需要根据我在问题上发布的算法或逻辑通过代码修复此问题