用的是Timer控件来刷新的。但是发现这个太占CPU了。多开几个就完蛋了。大家看看怎么处理。在不断的链接数据库。不是断开试么
- C# code
protected void Page_Load(object sender, EventArgs e) { } public void upload() { int nu = 0; Random random = new Random(); for (int i = 0; i < ListTest().Count; i++) { nu = random.Next(ListTest().Count); this.Label1.Text = ListTest()[nu].ToString(); } } public List<string> ListTest() { List<string> list = new List<string>(); Tab_Random zhinan_class = (Tab_Random)Tab_RandomManager.Instance.GetModelTab_RandomByWhere("numid=0 order by newid()"); list.Add(zhinan_class.Daqu); return list; } protected void Button1_Click(object sender, EventArgs e) { this.Timer1.Enabled = !this.Timer1.Enabled; Label2.Text = "".ToString(); } protected void Timer1_Tick(object sender, EventArgs e) { upload(); } protected void asdasda_Click(object sender, EventArgs e) { Tab_Random zhinan = (Tab_Random)Tab_RandomManager.Instance.GetModelTab_RandomByWhere("daqu='" + Label1.Text.ToString() + "'"); string dadada = zhinan.Daqu.ToString(); AnswerDAL.Intance.ModifyTab_Random(dadada); } protected void Button2_Click(object sender, EventArgs e) { AnswerDAL.Intance.ModifyTab_RandomAll(); } protected void Timer2_Tick(object sender, EventArgs e) { uploadone(); } public void uploadone() { int nu = 0; Random random = new Random(); for (int i = 0; i < ListTest().Count; i++) { nu = random.Next(ListTest().Count); this.Label2.Text = ListTestone()[nu].ToString(); } } public List<string> ListTestone() { List<string> list = new List<string>(); Tab_Random zhinan_class = (Tab_Random)Tab_RandomManager.Instance.GetModelTab_RandomByWhere("numid=0 and daqu='" + Label1.Text .ToString()+ "' order by newid()"); list.Add(zhinan_class.Name); return list; }
------解决方案--------------------------------------------------------
生成一堆数据然后用约瑟夫环之类的数据结构处理之。
------解决方案--------------------------------------------------------
每个Tick都从数据库里获取数据?
你周期设多长的?还有你这号抽来干嘛的
------解决方案--------------------------------------------------------
我觉得是你程序逻辑有问题,你想要的是从数据库里取出候选的记录,然后随机定时显示到界面上是吧?
你应该先执行一次数据库查询,比如放在pageload里,把结果保存在成员变量里。然后每次tick的时候随机从列表里选一个显示。100毫秒查询一次数据库对数据库压力很大的。
------解决方案--------------------------------------------------------