Timer 控件循环执行,如果子窗口已经打开就执行语句关闭 子窗口, 如果没有打开就打开子程序
FormCollection childCollection = Application.OpenForms;
for (int i = childCollection.Count; i-- > 0;)
{
if (childCollection[i].Name != "Monitor") childCollection[i].Close();
}
private Form open = null;
private void timer1_Tick(object sender, EventArgs e)
{
DataSet dt = SqlHelper.ExecuteDataset(connectionBu, "SUZ_UDP_PTS_GetMonitorConfig", BU, Type);
if (dt.Tables[0].Rows.Count > 0)
{
string connectionudp = dt.Tables[0].Rows[0][2].ToString();
string UdpName = dt.Tables[0].Rows[0][3].ToString();
ds = SqlHelper.ExecuteDataset(connectionudp, UdpName);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string LastSN = ds.Tables[0].Rows[i][1].ToString();
string NextSN = ds.Tables[0].Rows[i][2].ToString();
string Line = ds.Tables[0].Rows[i][3].ToString();
string Station = ds.Tables[0].Rows[i][4].ToString();
if (open == null || open.IsDisposed)//先判断子程序是否已经打开 ,如果已经打开就关闭
{
FormCollection childCollection = Application.OpenForms;
for (int j = childCollection.Count; j-- > 0;)
{
if (childCollection[j].Name != "Monitor") childCollection[j].Close();
}
Show aa = new Show();
aa.Show();
}
else
{
Show aa = new Show();
aa.Show();
}
}
}
else
{
FormCollection childCollection = Application.OpenForms;
for (int i = childCollection.Count; i-- > 0;)
{
if (childCollection[i].Name != "Monitor") childCollection[i].Close();
}
}
}
else
{
MessageBox.Show("没有配置Server/UDP , 请配置数据!(table :SUZ_UDT_GetMonitorConfig)");
}
}
本文介绍了一个使用C#实现的Timer控件应用案例,通过定时任务检查并更新子窗口状态。具体实现包括读取配置、检查子窗口是否已打开,以及相应的开启或关闭操作。
1507

被折叠的 条评论
为什么被折叠?



