| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1030 人关注过本帖
标题:webform 定时器
只看楼主 加入收藏
IC1805
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2022-1-14
收藏
 问题点数:0 回复次数:1 
webform 定时器
在winform中写的定时器代码,写在webform中无法运行。
目标: 想在webform中,做一个定时器,时间间隔1000毫秒,重复执行事件。
以下为winform中实验的程序。
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using


namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        System.Timers.Timer timer = new System.Timers.Timer(); // 实例化
        public Form1()
        {
            InitializeComponent();
        }
        int a=0;
        private void button1_Click(object sender, EventArgs e)
        {
         
            
                Action t = () =>
                {
                    textBox1.Text = a++.ToString();
                };
                Invoke(t);
            
               
           
        }
      
        private void button2_Click(object sender, EventArgs e)
        {
         
            timer.Interval = 1000; // 间隔时间
            timer.Elapsed += new System.Timers.ElapsedEventHandler(button1_Click); // 到时间后执行
            timer.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
            timer.Enabled = true;
            timer.Start();
        }
    }
}
搜索更多相关主题的帖子: webform using Timer System 定时器 
2022-01-14 13:53
fsbcwl
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-11-10
收藏
得分:0 
啥问题啊,运行很正常啊
2022-02-11 16:43
快速回复:webform 定时器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014875 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved