您的位置:首页 > 其它

event 自定义事件一例

2012-03-21 12:11 218 查看
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;

namespace ConsoleTest
{

public delegate void EventHandler(string sInfo);

class Class1
{
public event EventHandler EventHandleTest;

public void Start()
{
if (EventHandleTest != null)
{
Thread.Sleep(1000);
EventHandleTest("完成进度20%");
Thread.Sleep(1000);
EventHandleTest("完成进度40%");
Thread.Sleep(1000);
EventHandleTest("完成进度60%");
Thread.Sleep(1000);
EventHandleTest("完成进度80%");
Thread.Sleep(1000);
EventHandleTest("完成进度100%");
}
}
}

class customEvent
{
static void Main()
{
Class1 c = new Class1();
c.EventHandleTest +=new EventHandler(c_EventHandleTest);
c.Start();
Console.ReadLine();
}

public static void c_EventHandleTest(string sInfo)
{
Console.WriteLine(sInfo);
}

}
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  class string null c
相关文章推荐