日期:2014-05-17  浏览次数:20771 次

用System.Timers.Timer实时刷新数据
用System.Timers.Timer定时获取数据库的变化,如果有符合条件的变化则刷新页面数据,怎么写?
在aTimer.Elapsed += new ElapsedEventHandler(TimeEvent);里面写
        public void TimeEvent(object source, ElapsedEventArgs e)
        {
            string sql = "select top 1 content,rolling,row_id from text where ison=1";
            DataView dv = dbh.Executedv(sql);
            if (dv.Count == 1 && dv != null)
            {
                if (dv[0]["content"].ToString() != content)
                    System.Web.HttpContext.Current.Response.Write("<script>window.location.reload();</script>");
            }
        }
报错Response.Write未将对象引用设置到对象的实例

------解决方案--------------------
你怎么还问呢,System.Web.HttpContext.Current.Response这里面有null对象,自己调试啊
------解决方案--------------------
Response对象为null?
------解决方案--------------------

虽然不知道 刚刚上个问题是什么
但是页面同timer肯定不太好,还是用jquery的定时异步去请求,消耗的资源少。
------解决方案--------------------
引用:
虽然不知道 刚刚上个问题是什么
但是页面同timer肯定不太好,还是用jquery的定时异步去请求,消耗的资源少。