实在想不懂!请各位高手赐教!!(帮帮忙!很急)
我想在程序运行开始的时候执行一个timer,这个timer的触发事件中需要用到application的值,并且需要修改它的值!不知道我这样写到底对不对!每次便宜完之后出现:"发生类型为 System.StackOverflowException 的异常。" 这样的错误,请各位高手指点,或者给个其他思路.谢谢!
protected void Application_Start(Object sender, EventArgs e)
{
SetTimer( );
}
public void SetTimer( )
{
ConnectionStr cn=new ConnectionStr();
System.Timers.Timer aTimer = new System.Timers.Timer( cn.TimerValue );
aTimer.Elapsed+=new ElapsedEventHandler( OnTimedEvent );
// Only raise the event the first time Interval elapses.
aTimer.AutoReset = false;
aTimer.Enabled = true;
aTimer.Start( );
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
UserOnline useronline = new UserOnline( );
ConnectionStr cn=new ConnectionStr();
System.Web.HttpApplication Application = new HttpApplication( );
XmlDocument xmlDoc = new XmlDocument( );
xmlDoc.Load( cn.XmlStr );
XmlNodeList xnl=xmlDoc.SelectSingleNode("online").ChildNodes;
foreach(XmlNode xn in xnl)
{
XmlElement xe=(XmlElement)xn;
int timesub = 0;
if (System.Web.HttpContext.Current.Application[xe.InnerText+"login"]!=null)
{
TimeSpan ts = DateTime.Now.Subtract(Convert.ToDateTime( System.Web.HttpContext.Current.Application[xe.InnerText+"login"] ));
timesub = (int)ts.TotalMinutes;
}
if( timesub > cn.TimeOut )
{
useronline.DUserName( xe.InnerText );
System.Web.HttpContext.Current.Application.Remove(xe.InnerText+"login");
}
}
}