我在这里有一个事件 ServerStateReceived 检查 4 个服务器的状态,它们是 UP 还是 Down。所以所有 4 台服务器都关闭并且 ReadySent = true; 是我们需要关注的罕见案例。 我在这个方法中有一个方法 public write() 我需要一个逻辑来检查一个条件,如果标志 ReadySent = true; 并且所有服务器都在事件 ServerStateReceived 中关闭,如果满足控制应该转到事件 ServerStateReceived 。如果我在这里等待一段时间,那么所有 4 台服务器都将在那个时候启动,只有控制将来自 ServerStateReceived 事件来写入(),我不想使用睡眠()方法或挂起等,我需要一个逻辑这里通过代码
这是不是 c# 代码的算法
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)**