惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - 笑萧亦然

KingdeeK3-修改单据邮件发送的自定义字段 微软在GitHub上开放源代码 【转】GitHub入门详细讲解 asp.net 导出excel 中文乱码解决方法 (转) C#自动切换Windows窗口程序,如何才能调出主窗口? 系统颜色对照表 showModalDialog后如何刷新父页面 常用SQL关于表的操作 System.Web.HttpException 与 HTTP Error 404.13 - Not Found问题解决说明 SQL 数据库常用的系统存储过程解析 JAVA md5把我气到疯的代码,天哪,神呀,我的C# 啊。 根据经纬度坐标计算两点间几何距离 - 椰子树下 - CSDN博客 获取库中的所有字段的描述/获取某个表中所有字段方法 多个CSS风格共用同一(背景)图片_那一片天_百度空间 学习总结之三(SQL SERVER游标CURSOR的使用) SQL Server 如何锁一个表的某一行 - MS-SQL Server / 基础类 SQL中的系统变量一览 简单的弹出层窗口应用(DIV+JS) - 笑萧亦然 - 博客园 sql中左侧不够自动补0的写法,优!
delegate Demo (一个关于System.Timers.Timer的Demo)
笑萧亦然 · 2013-04-25 · via 博客园 - 笑萧亦然
namespace Delegates
{
    partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            clock = new Clock(digital);
        }

        private void start_Click(object sender, System.EventArgs e)
        {
            this.clock.Start();
        }

        private void stop_Click(object sender, System.EventArgs e)
        {
            this.clock.Stop();
        }

        private Clock clock;
    }
}

Clock.cs类的内容

namespace Delegates
{
    using System.Windows.Forms;

    class Clock
    {
        public Clock(TextBox displayBox)
        {
            this.display = displayBox;
        }

        public void Start()
        {
            pulsed.Add(this.RefreshTime);
        }

        public void Stop()
        {
            pulsed.Remove(this.RefreshTime);
        }

        private delegate void InvokeCallback(string msg);
        private void RefreshTime(int hh, int mm, int ss)
        {
            if (!this.display.InvokeRequired)
            {
                this.display.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", hh, mm, ss);
            }
            else
            {
                InvokeCallback msgCallback = new InvokeCallback(DisplayText);
                display.Invoke(msgCallback, new object[] { string.Format("{0:D2}:{1:D2}:{2:D2}", hh, mm, ss) });

            }

        }

        private void DisplayText(string text)
        {
            this.display.Text = text;
        }

        private Ticker pulsed = new Ticker();
        private TextBox display;



    }
}
namespace Delegates
{
    using System.Collections;
    using System.Timers;
    using System.Windows.Forms;

    class Ticker
    {
        public delegate void Tick(int hh, int mm, int ss);

        public Ticker()
        {
            this.ticking.Elapsed += new ElapsedEventHandler(this.OnTimedEvent);
            this.ticking.Interval = 1000; // 1 second
            this.ticking.Enabled = true;
        }

        public void Add(Tick newMethod)
        {
            this.tickers += newMethod;
        }

        public void Remove(Tick oldMethod)
        {
            this.tickers -= oldMethod;
        }

        private void Notify(int hours, int minutes, int seconds)
        {
            if (this.tickers != null)
            {
                this.tickers(hours, minutes, seconds);
            }

        }

        private void OnTimedEvent(object source, ElapsedEventArgs args)
        {
            int hh = args.SignalTime.Hour;
            int mm = args.SignalTime.Minute;
            int ss = args.SignalTime.Second;
            Notify(hh, mm, ss);
        }

        private Tick tickers;
        private System.Timers.Timer ticking = new System.Timers.Timer();
    }
}

Ticker.cs类的内容