asp.net后台服务更新前台数据应该如何更新?
服务层
namespace BusinessService {
public class BService {
Timer mTimer;
int second;
public BService() {
mTimer = new Timer(1000);
mTimer.Elapsed += new ElapsedEventHandler(mTimer_Elapsed);
}
void mTimer_Elapsed(object sender, ElapsedEventArgs e) {
second = DateTime.Now.Second;
if (OnDataReceived != null)
OnDataReceived(second, EventArgs.Empty);
}
public void StartService() {
mTimer.Start();
}
public void StopService() {
mTimer.Stop();
}
public int Second {
get { return second; }
}
public event OnDataReceivedDelegate OnDataReceived;
}
public delegate void OnDataReceivedDelegate(object sender, EventArgs ea);
}
想把这个更新到前台的页面上
namespace WebApplication1 {
public partial class WebForm1 : System.Web.UI.Page {
BService bService;
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
bService = new BService();
bService.OnDataReceived += new OnDataReceivedDelegate(bService_OnDataReceived);
bService.StartService();
}
}
void bService_OnDataReceived(object sender, EventArgs ea) {
Label1.Text = sender.ToString();
}
}
}
不知道前台刷新为什么没有数据更新???问题出在哪里? --------------------编程问答-------------------- 如果网站的数据 可以这样实时更新,,那么 推送也没什么意义了.. --------------------编程问答--------------------
这样也是一种数据推送啊,直接把数据推送给UI,剩下的都交由service处理了 --------------------编程问答-------------------- up up up up
补充:.NET技术 , C#