使用asp.net里的Timer从数据库获取数据时的怪异问题,有谁遇到过吗?
1。这是Global.asax里的代码:static public System.Timers.Timer xTimerSubmit = null;
void Application_Start(object sender, EventArgs e)
{
xTimerSubmit = new System.Timers.Timer(5 * 60 * 1000);
xTimerSubmit.Elapsed += new System.Timers.ElapsedEventHandler(xTimerSubmitElapsed);
xTimerSubmit.AutoReset = true;
xTimerSubmit.Enabled = true;
}
private void xTimerSubmitElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
APS.Execute();
}
2。这是APS.cs里的代码:
public static void Execute()
{
SubmitWaitingMsg(_Count, _SubmitTimeSpan);
}
private static void SubmitWaitingMsg(int _Count, int _SubmitSpan)
{
CFI.WriteLog( "APS", "Begin... ");
SqlParameter[] _Param = { new SqlParameter( "@SelRecCount ", SqlDbType.Int ),
new SqlParameter( "@SubmitTime ", SqlDbType.VarChar, 20 )
};
_Param[0].Value = _Count;
_Param[1].Value = (DateTime.Now.AddMinutes(_SubmitSpan)).ToString();
using (SqlDataReader _Reader = CDAI.GetDataReaderBySP(......))
{
if (_Reader == null) { CFI.WriteLog( "APS ", "No Reader "); return; }
if (!_Reader.HasRows) { CFI.WriteLog( "APS ", "No Data "); return; }
while (_Reader.Read())
{
......
}
_Reader.Dispose();
}
}
以上代码启动以后,Timer事件的确被触发了,因为CFI.WriteLog( "APS ", "Begin... ")这里写了日志,但是从数据库获取数据时而可以,时而得不到任何数据,这句CFI.WriteLog( "APS ", "No Data ")总是被执行。当获取不到数据的时候,此时有一个aspx页面,它有个Button,Button事件里的代码和SubmitWaitingMsg(...)代码段一模一样,却可以取到数据。真是百思不得其解。各位有谁知道如何处理这个问题吗?
ps:我第一次发贴,不知道自己有没积分。。。
补充:.NET技术 , ASP.NET