当前位置:编程学习 > C#/ASP.NET >>

Asp.Net中System.Threading.Timer问题?


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="MaintImplementSystem.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lbText" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>


后台:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MaintImplementSystem
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private static System.Threading.Timer timer;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                CustomTimer();
            }
        }
        int i = 0;
        private void SumFault(object obj)
        {
            i++;
            this.lbText.Text =i.ToString()+ "<br>";
        }
        private void CustomTimer()
        {

            timer = new System.Threading.Timer(SumFault, null, 0, 10000);

        }
    }
}



怎么运行后在页面看不到lbText的值 --------------------编程问答-------------------- --------------------编程问答-------------------- 因为页面显示完毕,你的SumFault还没有执行。
--------------------编程问答-------------------- 你的思路是Winform结构程序的,webform客户端和服务器是分开的。 --------------------编程问答--------------------  先去弄明白什么是web
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,