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

发布于 2024-09-12 19:42:34 字数 1934 浏览 4 评论 0原文

我在这里有一个 ServerStateReceived 事件检查 4 个服务器的状况,无论它们是处于 UP 还是 Down 状态。在这种特殊类型的场景中,服务器在开始时将处于关闭状态,但一段时间后服务器应该处于 Up 状态。因此所有 4 个服务器都处于关闭状态并 ReadySent =真;这是我们需要关注的罕见情况。 我在这个方法中有一个方法 public write() 我需要一个逻辑来检查条件,如果标志 ReadySent = true;并且在事件 ServerStateReceived 中所有服务器都已关闭,如果满足控制应转到事件 ServerStateReceived 。如果我在这里等待一段时间,所有 4 个服务器都会启动,此时只有控制权来自 ServerStateReceived 事件来 write(),,我不想使用 sleep() 方法或挂起等等,,我需要一个逻辑这里通过代码

这是算法,这不是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)**

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 will 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)**

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷情妓 2024-09-19 19:42:34
Public Write()
{
   System.Threading.Thread.Sleep(20000);
}

这会起作用,但我需要根据我在问题上发布的算法或逻辑通过代码修复此问题

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文