我需要显示一个计数器。当状态发生变化时,它会增加一个。如果状态从真变为假,它将增加1,但只会增加一次,再次增加。我的问题是我正在使用计时器,所以如果我的状态在1分钟内保持为假,计数器将显示60,并且它将增加1。我只需要增加一次..e.g如果它改变为真,它会增加一个。然后等待,如果状态回到真,然后再次假,那么它应该增加一,否则计数器将只是一个。帮我在取悦如何在状态发生变化时将计数器加1
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;
}
}
向我们显示您的代码。 –
我更新了我的问题 – ROMA