本帖最后由 lmm 于 2014-3-25 13:59 编辑
我觉得这种触发事件就和调用方法一样
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace 简单事件
- {
- public delegate void MyDelegate();
- class Program
- {
- public static event MyDelegate myEvent = null;
- static void Main(string[] args)
- {
- Console.WriteLine("主函数的线程ID: {0}", Thread.CurrentThread.ManagedThreadId);
- myEvent += new MyDelegate(func);
- myEvent();
- Console.WriteLine("主程序执行完毕");
- Console.ReadKey(true);
- }
- private static void func()
- {
- Console.WriteLine("当前的线程ID: {0}", Thread.CurrentThread.ManagedThreadId);
- Thread.Sleep(1000000);
- Console.WriteLine("test function");
- }
- }
- }
复制代码 可以看出这是顺序执行的. 线程ID都是Main函数的ID, 说明并没有单独建立线程.
|