我的日志记录模块总是抛“由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值”异常,而且此异常一出就把我的线程给停了,也无法捕获,求高手指教。附代码:
//创建后台线程往数据库里写日志
private static void Initialize()
{
LogStop = false;
interva = tempInterva;
sendThreadNum = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["DBLSendThreadNumber"].ToString());
tempInterva = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["DBLSendInterval"].ToString());
batchSend = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["DBLBatchSend"].ToString());
sendSleepTime = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["DBLSendSleepTime"].ToString()); if (LogQueue == null)
{
lock (CreateLock)
{
if (LogQueue == null)
{
LogQueue = new QueueList();
for (int i = 1; i <= sendThreadNum; i++)
{
//创建后台线程,不停的将数据信息写入数据库
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(WriteLogInto));
thread.IsBackground = true;
thread.Start();
System.Threading.Thread.Sleep(interva + i);
ThreadHash.Add("DBLog后台处理线程", thread);
}
}
}
}
}//将日志信息放入队列交给写日志进程处理
private static void WriteLogInto()
{
while (!LogStop)
{
try
{
//GC.Collect();
//GC.WaitForPendingFinalizers();
SendLogEntityByQueue();
System.Threading.Thread.Sleep(interva); }
catch//在此会捕获到标题中的异常,而且主线程在异常出现后不久就停止了,不知道为什么,而且每次捕获到异常的地方也不一样
{
XException xe = FuncLib.BuildXExcpetion("DBLog Happen A Exception", null);
LogRecordWrap.Send(xe.ToString(), PEConsts.LOG_EXCEPTION);
}
}
}//分批写日志
private static void SendLogEntityByQueue()
{
try
{
if (LogQueue != null)
{
if (LogQueue.Count > 0)
{
queueIsNull = false;
interva = tempInterva;
}
else
{
queueIsNull = true;
//如果队列中没有数据 触发延时阀值自动递增 10毫秒 当到达3000毫秒阀值时 系统自动停止增加
if (interva < 3000)
{
interva = interva + 10;
}
} int overCapacity = 0;
while ((LogQueue.Count > 0) && (overCapacity <= batchSend))
{
System.Threading.Thread.Sleep(sendSleepTime); CmdEntity log = DequeueLogEntity();
if (log != null)
{
try
{
log.OnCmdRun();//写日志
}
catch (Exception ex)
{
LogRecordWrap.Send(ex.ToString(), PEConsts.LOG_EXCEPTION);
//EnqueueLogEntity(log);
}
}
}
}
}
catch(Exception ex)
{
throw new Exception("DBLog.SendLogEntityByQueue Failed");
}
}
}//往数据库写日志
public override void OnCmdRun()
{
StringBuilder sb = new StringBuilder();
sb.Append(" Insert Into PhoneUserLoginRecord(PhoneUserID, LoginTime, LogoutTime)");
sb.Append(" Values(@PhoneUser_ID, @LoginTime, @LogoutTime) "); SqlParameter[] paras =
{
new SqlParameter("@PhoneUser_ID", SqlDbType.Int, 4),
new SqlParameter("@LoginTime", SqlDbType.DateTime),
new SqlParameter("@LogoutTime", SqlDbType.DateTime)
}; paras[0].Value = _UserID;
paras[1].Value = _CheckIn;
paras[2].Value = _CheckOut; //DbHelperSQL.ExecuteSql(sb.ToString(), paras); //update by Liming 2010-7-5 reason:捕获处理异常
try
{
DbHelperSQL.ExecuteSql(sb.ToString(), paras);
}
catch (Exception ex)
{
XException xe = FuncLib.BuildXExcpetion("AddUserBusinessTimeCmd数据库写入异常", ex);
xe.AddEnvironmentData("UserID", _UserID.ToString(), true);
xe.AddEnvironmentData("LoginTime", _CheckIn.ToString(), true);
xe.AddEnvironmentData("logoutTime", _CheckOut.ToString(), true);
log.Send(xe.ToString(), PEConsts.LOG_EXCEPTION, DateTime.Now.ToString("yyyy-MM-dd"));
}
}
//创建后台线程往数据库里写日志
private static void Initialize()
{
LogStop = false;
interva = tempInterva;
sendThreadNum = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["DBLSendThreadNumber"].ToString());
tempInterva = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["DBLSendInterval"].ToString());
batchSend = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["DBLBatchSend"].ToString());
sendSleepTime = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["DBLSendSleepTime"].ToString()); if (LogQueue == null)
{
lock (CreateLock)
{
if (LogQueue == null)
{
LogQueue = new QueueList();
for (int i = 1; i <= sendThreadNum; i++)
{
//创建后台线程,不停的将数据信息写入数据库
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(WriteLogInto));
thread.IsBackground = true;
thread.Start();
System.Threading.Thread.Sleep(interva + i);
ThreadHash.Add("DBLog后台处理线程", thread);
}
}
}
}
}//将日志信息放入队列交给写日志进程处理
private static void WriteLogInto()
{
while (!LogStop)
{
try
{
//GC.Collect();
//GC.WaitForPendingFinalizers();
SendLogEntityByQueue();
System.Threading.Thread.Sleep(interva); }
catch//在此会捕获到标题中的异常,而且主线程在异常出现后不久就停止了,不知道为什么,而且每次捕获到异常的地方也不一样
{
XException xe = FuncLib.BuildXExcpetion("DBLog Happen A Exception", null);
LogRecordWrap.Send(xe.ToString(), PEConsts.LOG_EXCEPTION);
}
}
}//分批写日志
private static void SendLogEntityByQueue()
{
try
{
if (LogQueue != null)
{
if (LogQueue.Count > 0)
{
queueIsNull = false;
interva = tempInterva;
}
else
{
queueIsNull = true;
//如果队列中没有数据 触发延时阀值自动递增 10毫秒 当到达3000毫秒阀值时 系统自动停止增加
if (interva < 3000)
{
interva = interva + 10;
}
} int overCapacity = 0;
while ((LogQueue.Count > 0) && (overCapacity <= batchSend))
{
System.Threading.Thread.Sleep(sendSleepTime); CmdEntity log = DequeueLogEntity();
if (log != null)
{
try
{
log.OnCmdRun();//写日志
}
catch (Exception ex)
{
LogRecordWrap.Send(ex.ToString(), PEConsts.LOG_EXCEPTION);
//EnqueueLogEntity(log);
}
}
}
}
}
catch(Exception ex)
{
throw new Exception("DBLog.SendLogEntityByQueue Failed");
}
}
}//往数据库写日志
public override void OnCmdRun()
{
StringBuilder sb = new StringBuilder();
sb.Append(" Insert Into PhoneUserLoginRecord(PhoneUserID, LoginTime, LogoutTime)");
sb.Append(" Values(@PhoneUser_ID, @LoginTime, @LogoutTime) "); SqlParameter[] paras =
{
new SqlParameter("@PhoneUser_ID", SqlDbType.Int, 4),
new SqlParameter("@LoginTime", SqlDbType.DateTime),
new SqlParameter("@LogoutTime", SqlDbType.DateTime)
}; paras[0].Value = _UserID;
paras[1].Value = _CheckIn;
paras[2].Value = _CheckOut; //DbHelperSQL.ExecuteSql(sb.ToString(), paras); //update by Liming 2010-7-5 reason:捕获处理异常
try
{
DbHelperSQL.ExecuteSql(sb.ToString(), paras);
}
catch (Exception ex)
{
XException xe = FuncLib.BuildXExcpetion("AddUserBusinessTimeCmd数据库写入异常", ex);
xe.AddEnvironmentData("UserID", _UserID.ToString(), true);
xe.AddEnvironmentData("LoginTime", _CheckIn.ToString(), true);
xe.AddEnvironmentData("logoutTime", _CheckOut.ToString(), true);
log.Send(xe.ToString(), PEConsts.LOG_EXCEPTION, DateTime.Now.ToString("yyyy-MM-dd"));
}
}
解决方案 »
- 谁能介绍个控件能把Excel直接绑定到页面进行操作啊
- 一个.net 2.0语法问题where TDataContext : DataContext, new()
- 正则表达式问题,我想匹配网页的除</p>和<p>以外的所有标签?
- 清除panel时间的sizechanged事件的所有委托
- 怎样用opengl沿任意曲线(由三维点列给出)生成圆柱?
- 在.NET 下将一个数据表的某个字段的值做为查询另一张表的WHERE条件.....
- winform有什么空件可以用来画表格
- [问题] 如何让进度条一遍又一遍的从头到尾的走,速度没有限定,差不多就行,直到某一函数结束。
- 水晶报表9时如何发布的
- 关于datagrid 和datatable的问题
- 加班发帖求教一个程序访问另一个exe中控件的问题。
- .Net线程管理
{
throw; //什么也不干
// XException xe = FuncLib.BuildXExcpetion("DBLog Happen A Exception", null);
//LogRecordWrap.Send(xe.ToString(), PEConsts.LOG_EXCEPTION);
}
}
DbHelperSQL有关闭数据库操作吗?