c#线程问题(3)

//执行回调函数


static
void Main(string[] args) { UPPER = 1000; Thread thread1=new Thread(sops); thread1.Name = "thread1"; thread1.Start(); Thread thread2=new Thread(sops); thread2.Name = "thread2"; thread2.Start(); Console.ReadLine(); } static void Callback(object o) { for (int i = 0; i < UPPER; i++) { Console.WriteLine(o); } } static void sops() { for (int i = 0; i < UPPER; i++) { Console.WriteLine("hello this data is {0}++++++++++++++++{1}", Thread.CurrentThread.Name, i); }  Console.WriteLine( Thread.CurrentThread.Name+"over"); ExecutionContext.Run(ExecutionContext.Capture(), new ContextCallback(Callback), Thread.CurrentThread.Name); } public static int UPPER { get; set; }

 

posted @ 2013-07-11 10:57  尼姑哪里跑  阅读(160)  评论(0编辑  收藏  举报