使用VS查看程序的IL代码

2910阅读 0评论2013-04-01 dyli2000
分类:C#/.net

在VS2008的命令行里面输入


  1. ildasm


然后按步骤操作。

image

图1

 

image 图2

 

image 图3

 

image

图4

图4源自下面的代码。


  1. namespace MinitorCase
  2. {
  3.     class Program
  4.     {
  5.         public static void MyLock()
  6.         {
  7.             lock (typeof(Program))
  8.             {
  9.             }
  10.         }
  11.         static void Main(string[] args)
  12.         {
  13.             MyLock();
  14.         }
  15.     }
  16. }



    可以看到,一个lock操作,在IL层时是被拆成一个Monitor.Enter和Monitor.Exit来完成的。

上一篇:多线程处理之lock语句
下一篇:C#线程系统讲座;同步与死锁