我想做的是 新消息提示 这样可以吗??
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
System.Timers.Timer t = new System.Timers.Timer(1000 * 10);//每10秒触发一次
t.AutoReset = true;
t.Enabled = true;
t.Elapsed += new System.Timers.ElapsedEventHandler(Fun);
}
private void Fun(object sender, System.Timers.ElapsedEventArgs e)
{
//这里是访问数据库的代码
string where = "TestState = 0";
ZCGLModel.f_Test_List list = ZCGLBLL.f_Test.Select_f_TestByTestState1(where);
if (ZCGLBLL.f_Test.GetCount(where) > 0)
{ //提示信息
}
}
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
System.Timers.Timer t = new System.Timers.Timer(1000 * 10);//每10秒触发一次
t.AutoReset = true;
t.Enabled = true;
t.Elapsed += new System.Timers.ElapsedEventHandler(Fun);
}
private void Fun(object sender, System.Timers.ElapsedEventArgs e)
{
//这里是访问数据库的代码
string where = "TestState = 0";
ZCGLModel.f_Test_List list = ZCGLBLL.f_Test.Select_f_TestByTestState1(where);
if (ZCGLBLL.f_Test.GetCount(where) > 0)
{ //提示信息
}
}
使用方法http://www.cnblogs.com/yjmyzz/archive/2009/06/14/1502921.html你也可以写个提醒的方法编译成DLL文件 然后通过数据库里写的触发器来调用自定义的CLR函数,通过CLR函数调用这个DLL文件里面写的提醒方法,进行提醒!
ASP.NET AJAX入门系列(10):Timer控件简单使用
http://www.cnblogs.com/Terrylee/archive/2006/11/14/Introduction_to_the_Timer_Control.html
2要和UI一个线程
3select 超过10秒时 timer tick 会累积
Web上基本没法实现Push,因此得用轮询,也就是用页面上用ajax Timer,定时检查,如果有更新,提示用户。
还有基于html5的websocket
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick" />
<span id="clock" runat="server"></span>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body> protected void Timer1_Tick(object sender, EventArgs e)
{
clock.InnerText=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}