正确的代码如下:
private void SetDate()
{
try
{
#region cpu载荷
SqlDataReader SqlReader = PCTK.DBUtility.DbHelperSql.ExecuteReader("SELECT Caption, IP_Address, CPULoad, PercentMemoryUsed, ResponseTime FROM Nodes WHERE (Comments = '服务器') AND (ObjectSubType = 'SNMP') AND (NodeID IN " +
" (SELECT NodeID FROM APM_Application)) ");
if (ServerList == null)
{
ServerList = new List<ModelSever>();
}
ServerList.Clear();
if (SqlReader != null)
{
while (SqlReader.Read())
{
PCTK.ModelSever ms = new ModelSever();
ms.ResponseTime = double.Parse(SqlReader["ResponseTime"].ToString());
if (ms.ResponseTime < 0)
{
ms.ResponseTime = 0;
}
ms.CPULoad = double.Parse(SqlReader["CPULoad"].ToString());
if (ms.CPULoad < 0)
{
ms.CPULoad = 0;
}
ms.PercentMemoryUsed = double.Parse(SqlReader["PercentMemoryUsed"].ToString());
if (ms.PercentMemoryUsed < 0)
{
ms.PercentMemoryUsed = 0;
}
ms.IPAddress = SqlReader["IP_Address"].ToString();
ms.Caption = SqlReader["Caption"].ToString();
ServerList.Add(ms);
}
}
SqlReader.Close();
SqlReader.Dispose();
#endregion
#region 饼图
SqlDataReader SReader = PCTK.DBUtility.DbHelperSql.ExecuteReader("select * from APM_Application_Sort_Count_V ");
if (Pie == null)
{
Pie = new List<double>();
}
if (SReader != null)
{
Pie.Clear();
Pie.Add(0.0);
Pie.Add(0.0);
Pie.Add(0.0);
while (SReader.Read())
{
double p;
if (SReader["LB"].ToString() == "正常")
{
p = double.Parse(SReader["SL"].ToString());
Pie[0] = p;
}
if (SReader["LB"].ToString() == "预警")
{
p = double.Parse(SReader["SL"].ToString());
Pie[1] = p;
}
if (SReader["LB"].ToString() == "告警")
{
p = double.Parse(SReader["SL"].ToString());
Pie[2] = p;
}
}
}
SReader.Dispose();
SReader.Close();
#endregion
#region 告警详细
SqlDataReader SqlReaderMessage = PCTK.DBUtility.DbHelperSql.ExecuteReader("SELECT EventTime, Message FROM Events WHERE (EventType >= 500) AND (EventType <= 505) AND (CONVERT(varchar, EventTime, 112) = CONVERT(varchar, GETDATE(), 112)) ORDER BY EventTime DESC");
if (EventInfo == null)
{
EventInfo = new List<ModelEvent>();
}
EventInfo.Clear();
if (SqlReaderMessage != null)
{
while (SqlReaderMessage.Read())
{
ModelEvent Me = new ModelEvent();
Me.DateTime = SqlReaderMessage["EventTime"].ToString();
Me.Message = SqlReaderMessage["Message"].ToString();
EventInfo.Add(Me);
}
}
SqlReaderMessage.Close();
SqlReaderMessage.Dispose();
#endregion
#region 可用性
if (AvailabilityList == null)
{
AvailabilityList = new List<ModelAvailability>();
}
SqlDataReader SqlReaderAvai = PCTK.DBUtility.DbHelperSql.ExecuteReader("SELECT CONVERT(varchar(10), b.DateTime, 120) AS Time, a.Name, a.ShortName, a.Type, b.PercentAvailability FROM (SELECT ID, Name, ShortName, Type " +
" FROM APM_Application WHERE (ZhanShi IS NULL)) AS a INNER JOIN (SELECT ApplicationID, DateTime, PercentAvailability FROM APM_DailyApplicationAvailability " +
" WHERE (CONVERT(varchar, DateTime, 112) = CONVERT(varchar, GETDATE(), 112))) AS b ON a.ID = b.ApplicationID ");
AvailabilityList.Clear();
if (SqlReaderAvai != null)
{
while (SqlReaderAvai.Read())
{
ModelAvailability MA = new ModelAvailability();
MA.XTMC = SqlReaderAvai["Name"].ToString();
MA.PercentAvailability = SqlReaderAvai["PercentAvailability"].ToString();
AvailabilityList.Add(MA);
}
}
SqlReaderAvai.Close();
SqlReaderAvai.Dispose();
#endregion
}
catch (Exception ex)
{
}
finally
{
if (IsClose == false)
{
GC.Collect();
GC.WaitForPendingFinalizers();
Thread.Sleep(5000);
SetDate();
}
else
{
thread1.Abort();
}
}
}
上面的代码执行数小时后报出如下错误:
如何解决?试了几种方法都无济于事。