请帮我看看这是咋回事啊,我的程序运行不到OnTimedEvent(),运行结果是:是什么啊3。
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Timers;
using System.Windows.Forms;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Timers.Timer aTimer = new System.Timers.Timer();
Button1.Text = "是什么啊1";
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = 2000;
Button1.Text = "是什么啊2";
aTimer.Enabled = true;
Button1.Text = "是什么啊3";
}
protected void OnTimedEvent(object source, ElapsedEventArgs e)
{
Button1.Text = "是什么4啊";
}
}
Web page 响应Button1事件请求后刷新页面并向客户端输出Button1.Text = "是什么啊3";然后Web page 就结束了,你设的这个定时器是一个异步调用,定时器到的时候,page已经处理完了。你这种应用用Timer是无法实现的,这和Winform程序是有区别的,建议使用AJAX。