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

推荐订阅源

人人都是产品经理
人人都是产品经理
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog
I
Intezer
Spread Privacy
Spread Privacy
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
TaoSecurity Blog
TaoSecurity Blog
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
H
Heimdal Security Blog
N
News | PayPal Newsroom
Attack and Defense Labs
Attack and Defense Labs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 【当耐特】
Webroot Blog
Webroot Blog
小众软件
小众软件
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
PCI Perspectives
PCI Perspectives
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
Cloudbric
Cloudbric
AI
AI
WordPress大学
WordPress大学
博客园 - 聂微东
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
Hacker News: Ask HN
Hacker News: Ask HN
H
Hacker News: Front Page
博客园 - Franky
V
V2EX
Schneier on Security
Schneier on Security
G
GRAHAM CLULEY
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
H
Help Net Security
量子位
S
Security @ Cisco Blogs
大猫的无限游戏
大猫的无限游戏
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recorded Future
Recorded Future
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
C
Cisco Blogs
S
Security Affairs

博客园 - 拼命郎

Gated Check-in function in TeamBuild 2010 关于asp.net2.0里的Multiview和View控件的显示与隐藏实现的问题 急死我了!!!vs 2005 单元测试 总是报错 读书笔记- programing .net components(o'Reilly) 由一个关于数据库操作类的写法而想到的。。。。 在sqlserver建表时尽量不要用特殊的字符,如[、]、回车等 关于嵌套事务的一种处理方法 关于.net 控件的html 属性的几点技巧 一个关于内容换行的问题 jbuilder 中不能调试的一种情况 几点关于java的代码常用规范 最近项目中一些关于代码编写管理的一些思考 几点asp.net的小收获 IsDbNull 方法的用法 两个概念:结构化和层次化的含义 一个char类型的字符赋给一个string对象时不会发生装箱操作 浅析.Net下的AppDomain编程 (转载) 属性(Attributs)笔记 操作符重载笔记
用事件和代理实现的一个闹钟实例
拼命郎 · 2006-01-12 · via 博客园 - 拼命郎

网速慢又不能插入代码,只好粘贴了
using System;

namespace Clock
{
public delegate void GetupNow();
 class home
 {
  /// <summary>
  /// 闹钟实现
  /// </summary>
  
  [STAThread]
  static void Main(string[] args)
  {
   Clock clock=new Clock();
   Man man=new Man();

   GetupNow getupNow;

   getupNow=new GetupNow(man.Getup);
   clock.getup+=new GetupNow(man.Getup);

   clock.Settime();
   clock.Ifring();
   Console.ReadLine(); 
   
  }
 }
 class Clock
 {
  public System.DateTime time;
  public event GetupNow getup;

  public void Settime()
  {
   int x=0;
   Console.WriteLine(System.DateTime.Now.ToShortDateString()+"请输入你要在多少毫秒后被叫醒");
   time=new DateTime();
   time=System.DateTime.Now;
   x=int.Parse(Console.ReadLine().Trim());
   time=time.AddSeconds(x);   
  }
  public void Ifring()
  {
    do
    {
     System.Threading.Thread.Sleep(1000); //休眠1000毫秒
     Console.WriteLine(time.Second-System.DateTime.Now.Second);//输出当前时间与响铃时间的差值
    }
    while
     (time.Second>System.DateTime.Now.Second);
    Ring();
    getup();
  }
  private void Ring()
  {
   Console.WriteLine("时间到");
  }

 }
 class Man
 {
    public void Getup()
  {
   Console.WriteLine("我起床了·!·!");
  }
 }
}
简单地说就是定义要通过事件调用的函数的代理,然后再将此代理注册到其他类中的事件上,在合适的时间调用。