private void timer1_Tick(object sender, EventArgs e) { string tmpstr = ""; if (m_ArrayContents != null) { if (richTextBox1.Lines.Length >= m_MaxLines) { //考虑到效率问题,先把内容复制到另外一个RichEdit中 richTextBox2.AppendText(richTextBox1.Text); richTextBox1.Clear(); } //此处有可能导致配置返回处理慢,需要考虑处理优化 if (m_ArrayContents.Count != 0) { tmpstr = m_ArrayContents[0] as string; richTextBox1.AppendText(tmpstr); richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.ScrollToCaret(); lock (m_ArrayContents) { m_ArrayContents.RemoveAt(0); } } } if (m_ServerInfoList != null) { BaseManage tmpManage = null; int index = 0; string tmpstatus = "未连接"; foreach (int id in m_ServerInfoList.Keys) { tmpManage = m_ServerInfoList[id] as BaseManage; if (listBox_Online.Items.Count >= (index + 1)) { switch (tmpManage.IdleFlag) { case -1: tmpstatus = "未连接"; break; case 0: tmpstatus = "空闲"; break; case 1: tmpstatus = "忙碌"; break; case 2: tmpstatus = "帐号密码错误"; break; case 3: tmpstatus = "工作号密码错误"; break; case 4: tmpstatus = "异常错误"; break; } int tmpsecondtime = PublicInfo.DateDiff(DateTime.Now, tmpManage.SetBusyTime); //检查配置,如果超过10秒钟仍为忙碌状态,则重新进行配置认证 if ((tmpManage.IdleFlag == 1) && (tmpsecondtime > 10)) { //设置为异常状态,等待重新进行配置认证 Log.Record("server.log", "配置:" + tmpManage.OriginalConfigManage.Original_ConfigName + "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber + ")" + tmpManage.OriginalConfigManage.Original_Ip + " 超过10秒钟仍为忙碌状态,设为状态为异常,等待重新进行配置认证..."); tmpManage.IdleFlag = 4; } if (tmpManage.EtermType == "地址认证") { listBox_Online.Items[index] = "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber.ToUpper() + ")" + tmpManage.OriginalConfigManage.Original_LocalIp + ":" + tmpManage.OriginalConfigManage.Original_Port.ToString() + " " + tmpstatus; } else { listBox_Online.Items[index] = "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber.ToUpper() + ")" + tmpManage.OriginalConfigManage.Original_ConfigName + ":" + tmpManage.OriginalConfigManage.Original_Port.ToString() + " " + tmpstatus; } index++; } else { if (tmpManage.EtermType == "地址认证") { listBox_Online.Items.Add("(" + tmpManage.OriginalConfigManage.Original_OfficeNumber.ToUpper() + ")" + tmpManage.OriginalConfigManage.Original_LocalIp + ":" + tmpManage.OriginalConfigManage.Original_Port.ToString() + " " + tmpstatus); } else { listBox_Online.Items.Add("(" + tmpManage.OriginalConfigManage.Original_OfficeNumber.ToUpper() + ")" + tmpManage.OriginalConfigManage.Original_ConfigName + ":" + tmpManage.OriginalConfigManage.Original_Port.ToString() + " " + tmpstatus); } } } } }
private void timer1_Tick(object sender, EventArgs e) { string tmpstr = ""; if (m_ArrayContents != null) { if (richTextBox1.Lines.Length >= m_MaxLines) { //考虑到效率问题,先把内容复制到另外一个RichEdit中 richTextBox2.AppendText(richTextBox1.Text); richTextBox1.Clear(); } //此处有可能导致配置返回处理慢,需要考虑处理优化 if (m_ArrayContents.Count != 0) { tmpstr = m_ArrayContents[0] as string; richTextBox1.AppendText(tmpstr); richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.ScrollToCaret(); lock (m_ArrayContents) { m_ArrayContents.RemoveAt(0); } } } if (m_ServerInfoList != null) { BaseManage tmpManage = null; int index = 0; string tmpstatus = "未连接"; foreach (int id in m_ServerInfoList.Keys) { tmpManage = m_ServerInfoList[id] as BaseManage; if (listBox_Online.Items.Count >= (index + 1)) { switch (tmpManage.IdleFlag) { case -2: tmpstatus = "正在连接"; break; case -1: tmpstatus = "未连接"; break; case 0: tmpstatus = "空闲"; break; case 1: tmpstatus = "忙碌"; break; case 2: tmpstatus = "帐号密码错误"; break; case 3: tmpstatus = "工作号密码错误"; break; case 4: tmpstatus = "异常错误"; break; } int tmpsecondtime = PublicInfo.DateDiff(DateTime.Now, tmpManage.SetBusyTime); //检查配置,如果超过10秒钟仍为忙碌状态,则重新进行配置认证 if ((tmpManage.IdleFlag == 1) && (tmpsecondtime > 10)) { //设置为异常状态,等待重新进行配置认证 Log.Record("server.log", "配置:" + tmpManage.OriginalConfigManage.Original_ConfigName + "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber + ")" + tmpManage.OriginalConfigManage.Original_Ip + " 超过10秒钟仍为忙碌状态,设状态为异常,等待重新进行配置认证..."); tmpManage.IdleFlag = 4; } //Kevin 2012-12-09修改 //如果配置长时间都是 “正在连接” 或 “配置异常”状态,则重启线程 tmpsecondtime = PublicInfo.DateDiff(DateTime.Now, tmpManage.SendCmdTime); //如果20秒还是正在连接状态,则重启线程 if ((tmpsecondtime > 20) && (tmpManage.IdleFlag == -2)) { //“正在连接”状态异常 Log.Record("heart.log", "配置:" + tmpManage.OriginalConfigManage.Original_ConfigName + "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber + ")" + tmpManage.OriginalConfigManage.Original_Ip + " 配置状态异常(超过20秒处于'正在连接'状态),重新启动线程进行配置认证..."); //启动专门的一个线程进行处理异常重启的配置 ///////////////////////////////////////// Thread tmpThread = new Thread(new ThreadStart(tmpManage.ReStartEterm)); tmpThread.Start(); } //发送心跳包异常重新启动配置 tmpsecondtime = PublicInfo.DateDiff(tmpManage.HeartStartTime, tmpManage.HeartEndTime); if (tmpManage.IdleFlag == 4) { //Log.Record("heart.log", "配置:" + tmpManage.OriginalConfigManage.Original_ConfigName + "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber + ")" + tmpManage.OriginalConfigManage.Original_Ip + // " 异常状态,心跳包间隔:"+tmpsecondtime.ToString()+"秒,发送心跳包时间:"+ // tmpManage.HeartStartTime.ToString("yyyy-MM-dd HH:mm:ss")+",接收心跳包返回时间:"+ // tmpManage.HeartEndTime.ToString("yyyy-MM-dd HH:mm:ss")); tmpsecondtime = PublicInfo.DateDiff(DateTime.Now, tmpManage.ErrorTime); if (tmpsecondtime > 60) { tmpManage.ErrorTime = DateTime.Now; } else { if (tmpsecondtime > 20) { Log.Record("heart.log", "配置:" + tmpManage.OriginalConfigManage.Original_ConfigName + "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber + ")" + tmpManage.OriginalConfigManage.Original_Ip + " 配置状态异常(超过20秒处于'异常'状态),重新启动线程进行配置认证..."); //启动专门的一个线程进行处理异常重启的配置 ///////////////////////////////////////// Thread tmpThread = new Thread(new ThreadStart(tmpManage.ReStartEterm)); tmpThread.Start(); } } } if ((tmpManage.IdleFlag != 0) && (tmpManage.HeartStartTime.CompareTo(tmpManage.HeartEndTime) > 0) && (tmpsecondtime > 10)) { //发送心跳包线程异常,需要重新启动线程 Log.Record("heart.log", "配置:" + tmpManage.OriginalConfigManage.Original_ConfigName + "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber + ")" + tmpManage.OriginalConfigManage.Original_Ip + " 发送心跳包间隔时间异常,重新启动线程进行配置认证..."); //启动专门的一个线程进行处理异常重启的配置 ///////////////////////////////////////// Thread tmpThread = new Thread(new ThreadStart(tmpManage.ReStartEterm)); tmpThread.Start(); } if (tmpManage.EtermType == "地址认证") { listBox_Online.Items[index] = "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber.ToUpper() + ")" + tmpManage.OriginalConfigManage.Original_LocalIp + ":" + tmpManage.OriginalConfigManage.Original_Port.ToString() + " " + tmpstatus; } else { listBox_Online.Items[index] = "(" + tmpManage.OriginalConfigManage.Original_OfficeNumber.ToUpper() + ")" + tmpManage.OriginalConfigManage.Original_ConfigName + ":" + tmpManage.OriginalConfigManage.Original_Port.ToString() + " " + tmpstatus; } index++; } else { if (tmpManage.EtermType == "地址认证") { listBox_Online.Items.Add("(" + tmpManage.OriginalConfigManage.Original_OfficeNumber.ToUpper() + ")" + tmpManage.OriginalConfigManage.Original_LocalIp + ":" + tmpManage.OriginalConfigManage.Original_Port.ToString() + " " + tmpstatus); } else { listBox_Online.Items.Add("(" + tmpManage.OriginalConfigManage.Original_OfficeNumber.ToUpper() + ")" + tmpManage.OriginalConfigManage.Original_ConfigName + ":" + tmpManage.OriginalConfigManage.Original_Port.ToString() + " " + tmpstatus); } } } } }