【发布时间】:2016-09-16 19:16:46
【问题描述】:
我需要显示一个计数器。当状态改变时它会加一。如果状态从真变为假,它会加一,但只有一次,然后在下一个假时它会再次增加。我的问题是我正在使用计时器,所以如果我的状态在 1 分钟内保持为假,计数器将显示 60,因为它增加了 1。我只需要增加一次 ..例如,如果它从 true 变为 false ,它将增加一。然后等待状态返回 true 然后再次为 false 然后它应该增加一,否则计数器将只是一。请帮帮我
void opc_status()
{
Int32 InRuntimeNumber = 0;
InRuntimeNumber = ModuleNetworkNode.OPCSystemsComponent1.InRuntime("192.168.1.2");
if (InRuntimeNumber == -1)
{
textBox.Text= "Service not reached";
}
else if (InRuntimeNumber == 1)
{
textBox.Text = "Active";
}
else
{
textBox.Text = "Stopped";
//rectangle_opc.Fill = new SolidColorBrush(Color.FromRgb(255, 226, 77));
}
public Boolean Status
{
get
{
return _status;
}
set
{
if (_status != value)
{
if (con.State != ConnectionState.Open)
{
con.Close();
con.Open();
}
SqlCommand cmd = new SqlCommand(" INSERT INTO Report (Date,Time, Event, [Type of Alarm]) VALUES ('" + DateTime.Now.Date.ToShortDateString() + "','" + DateTime.Now.ToString("t") + "','" + textBox.Text + "','" + "opc" + "')", con);
cmd.ExecuteNonQuery();
counterlabel.Content = counter++;
}
_status = value;
}
}
【问题讨论】:
-
向我们展示您的代码。
-
我更新了我的问题