码迷,mamicode.com
首页 > 其他好文 > 详细

SynchronizationContext的研究之一(非WPF及Forms)

时间:2014-05-07 02:18:18      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   tar   

bubuko.com,布布扣
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading;
 6 
 7 
 8 namespace SynchronizationTest003
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             SynchronizationContext sc = new SynchronizationContext();
15             Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
16             testA(sc);
17 
18             Console.ReadKey();
19         }
20 
21         public static void testA(object state)
22         {
23             SynchronizationContext sc = state as SynchronizationContext;
24             Console.WriteLine("Start");
25             Console.WriteLine("Func A‘s ManagedThreadID is: " + Thread.CurrentThread.ManagedThreadId);
26             sc.Post(testB,state);
27             Console.WriteLine("End");
28         }
29 
30         public static void testB(object state)
31         {
32             Console.WriteLine("Func B‘s ManagedThreadID is: " + Thread.CurrentThread.ManagedThreadId);
33             Thread.Sleep(3000);
34             SynchronizationContext sc = state as SynchronizationContext;
35             sc.Post(testC,null);
36         }
37 
38         public static void testC(object state)
39         {
40             Console.WriteLine("Func C‘s ManagedThreadID is: " + Thread.CurrentThread.ManagedThreadId);
41             Thread.Sleep(3000);
42             SynchronizationContext sc = state as SynchronizationContext;
43         }
44     }
45 }
bubuko.com,布布扣

运行结果:

bubuko.com,布布扣

SynchronizationContext的研究之一(非WPF及Forms),布布扣,bubuko.com

SynchronizationContext的研究之一(非WPF及Forms)

标签:style   blog   class   code   java   tar   

原文地址:http://www.cnblogs.com/AmitX-moten/p/3712171.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!