我想做一个定时查询数据库,根据查询结果弹出对话框的功能,但是现在遇到了一些麻烦,我在全局页global.asax.cs里写上一下代码:
protectedvoidApplication_Start(objectsender,EventArgse)
{System.Data.SqlClientSQL=newSystem.Data.SqlClient();
//定义一个定时器
System.Timers.TimerTimer=newSystem.Timers.Timer(5000);//5s触发一次
Timer.Elapsed=newElapsedEventHandler(Task);
Timer.Enabled=true;
Timer.AutoReset=true;
Timer.Start();
}
voidTask(objectsource,ElapsedEventArgse)
{//查询数据库,如果符合要求,就调用showtip()弹出提示对话框,不符合要求则不做任何操作。}
protectedvoidshowtip()
{Response.Write(\"Scriptwindow.open(\'autoopenwincontent.aspx\',\'_blank\',\'height=150,width=250,left=0,top=0,menubar=no,toolbars=no,location=no,directories=no,scrollbars=no,status=no,resizable=no\');/script\");
}}
我把Task的内容单独放在普通页面,用按钮触发可以实现。现在想让它自动查询,但是整个程序却没有执行这个定时查询。我在这里就想请教各位路过的大虾,到底是怎么回事,我该怎么实现这个功能?最好能具体点,谢谢了!
|