您的位置:知识库 »

Visual Studio 2005中编译调试新功能

作者: jackyrong的世界  来源: 博客园  发布时间: 2008-09-09 10:37  阅读: 2403 次  推荐: 0   原文链接   [收藏]  

Just My Code Debugging

 

  在调试代码中,我们经常会遇到这样的问题,有时我们引用了一些其他工具包或者类库(如Microsoft提供的Enterprise Library),而在调试时,我们其实是不需要跟踪调试这些代码的,因为它们都已经证明是正确的。在Visual Studio 2003中,处理这类问题我们的方法一般是使用F10跳过它们,但一旦工程庞大的话,这样做十分麻烦。在Visual Studio 2005中,新增加了Just My Code debugging(JMC)的新特性,可以让开发者自己定制哪些代码是需要调试,哪些代码是永远不需要调试的,这样可以节省大量的时间。

  JMC功能由两方面来实现。首先,如果一个工程是以release方式进行编译构建的话(就是工程中,没有pdb文件),调试器会将其认为是非用户代码,那么在调试运行时,就根本不会进入该工程中进行调试。其次,可以使用System.Diagnostics命名空间里的DebuggerNonUserCodeAttribute属性,将其应用在希望不进行调试的代码段中。

  下面举一个例子来说明。下面的代码段中,有两个静态方法UserCode()和NonUserCode(),其中,在NonUserCode()中,是应用了DebuggerNonUserCode的属性,这表明这段代码将在调试运行时,调试器不会进入其中。将断点设置在其中的第9行,运行程序,程序会在第一个UserCode()里中断,现在试着用F11继续单步跟踪,会发现系统在进入usercode()方法中运行后,并没有进入到NonUserCode()里运行。

 


using System;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
// Step into F11 from here
UserCode();// Place break point on this line
NonUserCode();
UserCode();
}
static void UserCode()
{
Console.WriteLine(
"This is a call from user Code");
}
// Attribute to indicate the Debugger to jump
// over this method
[DebuggerNonUserCode]
static void NonUserCode()
{
Console.WriteLine(
"This is a call fron Non User Code");
}
}

 

 

0
0
 

热门文章

    最新文章

      最新新闻

        热门新闻