Enums and flags checks in a given environmental condition
I have a event ServerStateReceived here checking condition of 4 servers whether they are UP or Down going on.In this particular type of scenario server will be down on beginning but after sometime server should be Up.So all 4 servers down and ReadySent = true; is a rare case we need to look . I have a method public write() in this method I need a logic to check a condition that if the flag ReadySent = true; and all servers Are DOWN in the event ServerStateReceived,if it satisying control should go to event ServerStateReceived . if I wait here for some time the all 4 servers will be UP in that time only control wi开发者_JS百科ll come from ServerStateReceived event to write(),,I don’t want to use sleep() method or suspend etc,,I need a logic Here through code
This is the algorithm for that this is not 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
}
}
Here is the c# code where i need to implement above logic
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)**
Public Write()
{
System.Threading.Thread.Sleep(20000);
}
This will work but I need an fix for this through code on based on the algorithm or logic I have posted on the question
精彩评论