---
title: "Visual Studio 2008 每日提示(三十一)"
author: "cjc"
date: "2009-03-03T01:09:00Z"
tags: []
slug: "visual-studio-2008"
draft: false
lastmod: "2009-03-03T01:09:00Z"
id: 402646
url: "https://cjc.iteye.com/blog/402646"
---

&lt;script&gt;function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}&lt;/script&gt;

本篇包括tip311-tip320  
[http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-31.html](http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-31.html)

## #311、按Shift+F11跳出函数

原文链接：[You can press Shift+F11 to step out of a function](http://blogs.msdn.com/saraford/archive/2008/09/11/did-you-know-you-can-press-shift-f11-to-step-out-of-a-function-311.aspx)

**操作步骤：**  
在调试状态，断点停留在一个函数的内部  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowYoucanpressShiftF11tostepoutof_124C5/image_thumb.png)

可以按**Shift+F11**从函数的任何位置跳出函数。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowYoucanpressShiftF11tostepoutof_124C5/image_thumb_1.png)

**评论：用Shift+F11跳出函数让我们直之关注需要了解的函数部分，对于不想知道的部分直接跳出。**

[http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-31.html](http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-31.html)

## #312、在[调试器](http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-31.html)里没有‘继续’命令

原文链接：[There’s no command for Continuing the debugge](http://blogs.msdn.com/saraford/archive/2008/09/12/did-you-know-there-s-no-command-for-continuing-the-debugger-312.aspx)r

**操作步骤：**  
注意启动图标的提示的变化，在"调试.启动"命令是是“启动调试”  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowTheresnocommandforContinuingth_126A1/image_thumb.png)

继续调试时，是提示“继续”  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowTheresnocommandforContinuingth_126A1/image_thumb_1.png)

我们也许会想：当然应该有和两个快捷键相对应的命令。那么“继续”的命令是什么呢？你会发现原来没有“调试.继续”这个命令，而只有“调试.启动”命令。在调试模式下提示只是被改名了（并没产生新的命令）。

**评论：这些细节对于很少用命令的程序员也许很难发现，对作者这样的测试人员却不能放过。**

## #313、不使用断点来中断调试

原文链接：[You can break the debugger without using Breakpoints](http://blogs.msdn.com/saraford/archive/2008/09/15/did-you-know-you-can-break-the-debugger-without-using-breakpoints-313.aspx)

**操作步骤：**  
如果你使用时VB,可以在中断执行的代码处添加“**stop**”关键字，这个stop语句相当于添加一个断点。有时候，输入一个“stop”比记住单击F9 或去拿鼠标更快。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowYoucanbreakthedebuggerwithoutu_106F2/image_thumb_1.png)

如果你使用的c#，可以在你的代码里使用“**Debugger.Break(**)”来中断调试，只有你使用System.Diagnostics名称空间才是这样。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowYoucanbreakthedebuggerwithoutu_106F2/image_thumb.png)

**评论：这种加中断的方法，你估计用的不多吧。**

## #314、创建对象ID跟踪你的对象

原文链接:How to create an Object ID to keep track of your objects

**操作步骤：**  
（调试状态）在你打开对象的实例的数据提示时候，在右键菜单里你会发现“**创建对象ID**”  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.HowtocreateanObjectIDtokeeptrackofyo_11664/image_thumb_3.png)

如果你单击“创建对象ID”，你会发现**{1#}**被增加在（对象的）值的内容里面。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.HowtocreateanObjectIDtokeeptrackofyo_11664/image_thumb_1.png)

你也可以在自动和监视窗口发现它  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.HowtocreateanObjectIDtokeeptrackofyo_11664/image_thumb_2.png)

如果你要再次看见这个变量，你可以在监视窗口应用对象的ID,如下图所示  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.HowtocreateanObjectIDtokeeptrackofyo_11664/image_thumb_6.png)

你可以删除对象ID，在右键菜单，或者监视（局部或自动）窗口。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.HowtocreateanObjectIDtokeeptrackofyo_11664/image_thumb_4.png)

**评论：从Visual Studio 2005开始，引入了"Object Identity While Debugging"的概念，也就是说，系统给在调试阶段的每个对象，都可以赋予一个别名，在调试时，直接引用该别名就可以了。假设在调试的时候，需要跟踪比如dataset或者hashtable等对象，这些对象中包含了很多其他的子对象，如果想对这些数量众多的子对象进行跟踪的话，将十分麻烦。在Visual Studio 2005中，可以使用object identity(对象标识)的方法去标记每一个对象.**

## #315、如何用找回源码对话框代替“没有可用的源码”消息

原文链接:[How to get the Find Source dialog back instead of the "There is no source code available" message](http://blogs.msdn.com/saraford/archive/2008/09/17/did-you-know-how-to-get-the-find-source-dialog-back-instead-of-the-there-is-no-source-code-available-message-315.aspx)

**操作步骤：**  
有时候，你正在调试的时候，vs不知道源码的位置在哪，vs会给你一个确认框，要求你指定源码的位置。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.HowtogettheFindSourcedialogbackinste_11EF3/image_thumb.png)

如果你小心点击了“取消”按钮，会提示你“在当前位置没有可用的源码”  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.HowtogettheFindSourcedialogbackinste_11EF3/image_thumb_1.png)

这时候，如果你停止，再试一次，你会发现查找代码位置的对话框不再出现了。vs会直接提示你“没有可用的源代码”，即使你想再次告诉vs源码的位置，也没办法了。

解决办法如下：  
**右键点击“解决方案”+“通用属性”+“调试源码文件”**，有个“**不查找这些源文件**”的文本框  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.HowtogettheFindSourcedialogbackinste_11EF3/image_thumb_3.png)  
删除文件所对应的行后，就可以在调试中再次出现查找源码的对话框。

**评论：这么细微的功能你没注意吧。**

## #316、自动窗口和局部窗口的差异

原文链接:[What's the difference between the Autos window and the Locals window](http://blogs.msdn.com/saraford/archive/2008/09/18/did-you-know-what-s-the-difference-between-the-autos-window-and-the-locals-window-316.aspx)

**操作步骤：**  
**自动窗口**：显示当前声明和上一声明。  
**局部窗口**：显示范围内所有声明。自动窗口是局部窗口的子集。  
例如，如下代码段，不做任何事，只产生未使用变量的警告。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.WhatsthedifferencebetweentheAutoswin_12CBA/image_thumb.png)

在自动窗口，你可以看见上一个声明和当前声明被运算。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.WhatsthedifferencebetweentheAutoswin_12CBA/image_thumb_1.png)

在局部窗口，你会看见所有的声明，包括参数  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.WhatsthedifferencebetweentheAutoswin_12CBA/image_thumb_2.png)

**评论：如果你关注更多的声明运算建议你用局部窗口，如果你只关注当前声明的话最好用自动窗口。**

## #317、在控制台程序中用Ctrl+F5让控制台停留在打开的状态

原文链接:[If you do a Ctrl+F5 on a console application, the console stays open](http://blogs.msdn.com/saraford/archive/2008/09/19/did-you-know-if-you-do-a-ctrl-f5-on-a-console-application-the-console-stays-open-317.aspx)

**操作步骤：**  
在控制台程序中，启动调试，如果没有“stop/Debugger.Break()”或某种Console.Read()方法，控制台就会瞬间出现然后消失。

如果你按**Ctrl+F5**启动程序而不调试，在底部就会出现“按任意键继续”的消息。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.IfyoudoaCtrlF5onaconsoleapplicationt_1308B/image_thumb.png)

**评论：作者对此颇有疑问，不太理解为什么在调试状态控制台会一闪而过，而看不到任何调试信息。这个问题确实让人有些费解。**

## #318、在监视窗口增加$exception变量来捕获异常

原文链接:[You can add $exception to the Watch window to see the caught exception](http://blogs.msdn.com/saraford/archive/2008/09/22/did-you-know-you-can-add-exception-to-the-watch-window-to-see-the-caught-exception-318.aspx)

**操作步骤：**  
如果你想迅速知道异常是否被捕捉，而不必再try catch 中找出异常的变量名，你可以在监视窗口输入：$exception  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.YoucanaddexceptiontotheWatchwindowto_1393A/image_thumb.png)

**评论：这个方法非常不错，在try catch里看是否捕捉了异常，速度很快。**

## #319、使用文本可视化工具

原文链接:[How to use the Text Visualizer](http://blogs.msdn.com/saraford/archive/2008/09/23/did-you-know-how-to-use-the-text-visualizer-319.aspx)

**操作步骤：**  
例如你有一些很长的字符串，也许是sql链接字符串或者只是一些表格数据，如果你需要查看真个字符串。  
当然你可以把这些字符串复制到记事本去查看内容，不过，在vs里也可以实现这个功能。  
打开字符串数据提示，单击下拉箭头  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowHowtousetheTextVisualizer319_1235D/image_thumb_1.png)  
你会发现可视化的工具供选择  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowHowtousetheTextVisualizer319_1235D/image_thumb.png)

因为是字符串，所以选择“文本可视化工具”。注意这个对话框可以调整大小，也可以从里面复制和粘贴。

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowHowtousetheTextVisualizer319_1235D/image_thumb_3.png)

**评论：文本可视化工具是我用的最多的可视化工具了，看比较成的sql语句非常方便。**

## #320、文本可视化工具支持文字换行

原文链接: [The Text Visualizer supports word wrap](http://blogs.msdn.com/saraford/archive/2008/09/24/did-you-know-the-text-visualizer-supports-word-wrap-320.aspx)

**操作步骤：**  
在可视化文本工具底部有个选择切换"换行"的选项，给你一种记事本的体验。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowTheTextVisualizersupportswordw_12954/image_thumb.png)

如果不选择该项，文字就会超出对话框的范围。  
![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/DidyouknowTheTextVisualizersupportswordw_12954/image_thumb_1.png)

**评论：如果不换行，看起来就太痛苦了。**

更多有关Visual Studio 2008 每日提示文章见：[Visual Studio 2008 每日提示系列索引](http://blog.csdn.net/xjbx/archive/2009/01/17/3818780.aspx)

更多文章见：[守望轩](http://www.watch-life.net/)\[[http://www.watch-life.net](http://www.watch-life.net/)/]