Sends for the fellow dear visitors:welcome to dongpad!


 Welcome to DongPad!

 msn


预览模式: 普通 | 列表

Net体系结构图

This Article is Published by Live Writer。

image

原文地址

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 468 | 返回顶部

Applications = Code + Markup读书笔记(2)

This Article is Published by Live Writer。

1.由RGB三原色组成的颜色空间也叫sRGB颜色空间,sRGB空间将显示点阵图像的做法正式化
The RGB color space implied by byte values of red, green, and blue primaries is sometimes

known as the sRGB color space, where s stands for standard. The sRGB space formalizes

common practices in displaying bitmapped images from scanners and digital cameras on

computer monitors. When used to display colors on the video display, the values of the sRGB

primaries are generally directly proportional to the voltages of the electrical signals

sent from the video display board to the monitor.

2.引入了scRGB的概念,也被称为sRGB64
关于scRGB的Wikipedia: http://en.wikipedia.org/wiki/ScRGB

3.sRGB三原色存储类型为byte,scRGB三原色存储类型为float,由于scRGB可以大于1或小于0,所以scRGB颜

色空间更大

4.Brush体系结构
Object
└─DispatcherObject (abstract)
   └─DependencyObject
      └─Freezable (abstract)
         └─Animatable (abstract)
            └─Brush (abstract)
               ├─GradientBrush (abstract)
               │ ├─LinearGradientBrush
               │ └─RadialGradientBrush
               │
               ├─SolidColorBrush
               │
               └─TileBrush (abstract)
                  ├─DrawingBrush
                  ├─ImageBrush
                  └─VisualBrush

5.关于Brush的动态事件机制,如上结构图,Brush继承自Freezable,而Freezable实现了changed事件,所以

只要Brush改变,都会通知事件的订阅者,该示例中就是通知Window来重绘窗体了,这一点需要和Winform进

行区分,Winform中除非人为处理,否则更改颜色不会触发窗体绘制
Obviously somebody is redrawing the client area every time the brush changes, but it's all

happening behind the scenes. This dynamic response is possible because Brush derives from

the Freezable class, which implements an event named Changed. This event is fired whenever

any changes are made to the Brush object, and this is how the background can be redrawn

whenever a change occurs in the brush.

This Changed event and similar mechanisms are used extensively behind the scenes in the

implementation of animation and other features in the Windows Presentation Foundation.

6.Brushes.PaleGoldenrod和new SolidColorBrush(Colors.PaleGoldenrod)虽然得到的是相同的brush,

但是在使用的时候要考虑到前者不允许被修改,因为前者是一个静态只读属性,还需要注意到Frozen的相关概念
The SolidColorBrush objects returned from the Brushes class are in a frozen state, which

means they can no longer be altered

7.LinearGradientBrush及RadialGradientBrush的一些属性和示例应用

活学活用,切勿读死书 @_@

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 368 | 返回顶部

CREATING A GLASS BUTTON: THE COMPLETE TUTORIAL

This Article is Published by Live Writer。

Well, it was a while back that I posted the first Creating a Glass button tutorial. Of course, that was based on the old look of Sparkle, and I have had some feedback recently that the project doesn't run anymore. Also, the completed tutorial never 'made it to press' leaving people with a rather lifeless button.

Well folks - GREAT NEWS - I have finished working on a all new glass button. And what better design to follow than some of the glass buttons in our shiny new OS.

Windows Vista task bar

The Windows Vista taskbar has some real nice buttons - they are see through and have an internal glow. So, I though I would base my all new complete glass button tutorial on these babies. I also hope there is enough content in the tutorial to help you explore other designs and other controls.

picture of the glass buttons app runing

So, attached to this post are the full instructions for creating the buttons above. I have also attached the finished project if you want to explore what I have done.

This has been a while coming, so please enjoy!

Attachment(s): CreatingTheGlassButton.zip

From:Martin Grayson

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 472 | 返回顶部

LINQ学习笔记及总结(1)

完整下载:/Files/DongPad/LINQApp.7z

//【一个比较简单的需求,找出年龄大于25小于30的Person】
List lpsTmp = new List{
new Person{ID=1000,Name="A",Age=24},
new Person{ID=1001,Name="B",Age=26},
new Person{ID=1002,Name="C",Age=28},
new Person{ID=1003,Name="D",Age=30},
new Person{ID=1004,Name="E",Age=32}
};
//-------------------------------------------------------
//【方式1】如果是在net1.1(1.1中还没有引入泛型概念)或2.0中,直接遍历
Console.WriteLine("方式1");
foreach (Person p in lpsTmp)
{
if (p.Age > 25 && p.Age < 30)
    {
        Console.WriteLine(string.Format("{0}'s ID is {1},{2} years old", p.Name, p.ID, p.Age));
    }
}
//-------------------------------------------------------
//-------------------------------------------------------
//【方式2】使用List的FindAll来实现,这里主要用到了2.0里的Predicate泛型委托
// Predicate可以省略
Console.WriteLine("\r\n方式2");
lpsTmp.FindAll(new Predicate(FindMatchPerson2));
//或
lpsTmp.FindAll(FindMatchPerson2);
//-------------------------------------------------------
//-------------------------------------------------------
//【方式3】方式2中我们需要额外的定义一个方法用来匹配集合中的对象
//我们可以使用更简洁的语法,那就是匿名方法, Predicate可以省略
Console.WriteLine("\r\n方式3");
lpsTmp.FindAll(new Predicate(delegate(Person p)
{
if (p.Age > 25 && p.Age < 30)
    {
        Console.WriteLine(string.Format("{0}'s ID is {1},{2} years old", p.Name, p.ID, p.Age));
return true;
    }
return false;
}));
//或
lpsTmp.FindAll(delegate(Person p) { return true; });
//-------------------------------------------------------
//-------------------------------------------------------
//【方式4】方式3中我们通过匿名方法避免了去定义一个额外的判断方法
//接下来我们来使用lambda表达式实现同样的效果
//Lambda表达式实际上为书写匿名方法提供了一种更加简单、更加函数化的语法
Console.WriteLine("\r\n方式4");
var lsps4 = lpsTmp.FindAll(new Predicate(p => p.Age > 25 && p.Age < 30));
//或
lsps4 = lpsTmp.FindAll(p => p.Age > 25 && p.Age < 30);
foreach (Person p in lsps4)
    Console.WriteLine(string.Format("{0}'s ID is {1},{2} years old", p.Name, p.ID, p.Age));
//-------------------------------------------------------
//-------------------------------------------------------
//【方式5】接下来我们使用Linq的一些静态方法,实际上List的一些扩展方法,Func可以省略
Console.WriteLine("\r\n方式5");
var lsps5 = System.Linq.Enumerable.Where(lpsTmp, new Func(FindMatchPerson2)).ToList();
//或
lsps5 = System.Linq.Enumerable.Where(lpsTmp, FindMatchPerson2).ToList();
//上面的【方式5】与【方式2】比较类似,都是委托给FindMatchPerson2来执行
//下同【方式3】,使用了匿名方法,可以省略Func
lsps5 = System.Linq.Enumerable.Where(lpsTmp, new Func(delegate(Person ppTmp)
{
if (ppTmp.Age > 25 && ppTmp.Age < 30)
    {
        Console.WriteLine(string.Format("{0}'s ID is {1},{2} years old", ppTmp.Name, ppTmp.ID, ppTmp.Age));
return true;
    }
return false;
})).ToList();
//下同【方式4】,使用lambda表达式,可以省略Func
lsps5 = System.Linq.Enumerable.Where(lpsTmp, new Func(p => p.Age > 25 && p.Age < 30)).ToList();
//-------------------------------------------------------
//-------------------------------------------------------
//【方式6】接下来我们使用List的一些扩展方法,这主要是为了接下来使用Linq做个铺垫
//因为linq的本质就是使用扩展方法扩展了对集合类型的各种查询方法,Func可以省略
Console.WriteLine("\r\n方式6");
var lsps6 = lpsTmp.Where(new Func(FindMatchPerson2)).ToList();
//或
lsps6 = lpsTmp.Where(FindMatchPerson2).ToList();
//上面的【方式6】与【方式2】比较类似,都是委托给FindMatchPerson2来执行
//下同【方式3】,使用了匿名方法,可以省略Func
lsps6 = lpsTmp.Where(new Func(delegate(Person ppTmp)
{
if (ppTmp.Age > 25 && ppTmp.Age < 30)
    {
        Console.WriteLine(string.Format("{0}'s ID is {1},{2} years old", ppTmp.Name, ppTmp.ID, ppTmp.Age));
return true;
    }
return false;
})).ToList();
//下同【方式4】,使用lambda表达式,可以省略Func
lsps6 = lpsTmp.Where(new Func(p => p.Age > 25 && p.Age < 30)).ToList();
//-------------------------------------------------------
//-------------------------------------------------------
//【方式7】最后我们使用Linq语法来实现同样的效果
Console.WriteLine("\r\n方式7");
var lsps7 = from p in lpsTmp where p.Age > 25 && p.Age < 30 select p;
foreach (Person p in lsps7)
    Console.WriteLine(string.Format("{0}'s ID is {1},{2} years old", p.Name, p.ID, p.Age));
//-------------------------------------------------------
//-------------------------------------------------------
//通过这里列出的几种实现方式,我们会发现用来实现的代码越来越简洁,随之提升将不仅仅是编码效率哦.吼吼!!!
//这里除了Linq,成员方法,静态方法和扩展方法都可以分别使用命名委托、匿名委托或Lambda表达式作为参数!!!
//这里代码演变到简洁的过程如下:
//命名委托==>匿名委托==>Lambda表达式
//成员方法(list.FindAll)==>静态方法==>扩展方法==>Linq
//综上所述,Linq的本质无外乎委托,整一个活生生的"语法糖",他把许多东西都交给编译器来处理了
//由此可见,在学习的过程中举一反三还是比较重要的,知其然更要知其所以然,通过了解本质,对于我们来说将更容易掌握知识,应用知识!!!
//所涉及之处,难免会存在一些问题,诚恳希望大伙们能够提出并一起讨论!!!
//参考资料:《LINQ-the future of data access in c# 3.0》
//-------------------------------------------------------


Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 356 | 返回顶部

44个Silverlight 视频讲座

This Article is Published by Live Writer。

01. Silverlight - Hello World
02. Silverlight - Anatomy of an Application
03. Silverlight - The VS Environment
04. Silverlight - Content Controls
05. Silverlight - Built-In Controls
06. Silverlight - Width, Height, Margins, Padding, Alignment
07. Silverlight - Using a GridSplitter
08. Silverlight - Grid Layout
09. Silverlight - StackPanel Layout
10. Silverlight - Canvas Layout
11. Silverlight - Databinding UI to .NET Classes
12. Silverlight - Simple Styles
13. Silverlight - Custom Types in XAML
14. Silverlight - Binding with Conversion
15. Silverlight - List Based Data Binding
16. Silverlight - Simple User Control
17. Silverlight - Templating a Button
18. Silverlight - Resources from XAP/DLL/Site Of Origin
19. Silverlight - Animations & Storyboards
20. Silverlight - Uploads with WebClient
21. Silverlight - Downloads with WebClient
22. Silverlight - Calling HTTPS Web Services
23. Silverlight - Calling Web Services
24. Silverlight - Making Cross Domain Requests
25. Silverlight - Using HttpWebRequest
26. Silverlight - File Dialogs and User Files
27. Silverlight - Using Sockets
28. Silverlight - Using Isolated Storage
29. Silverlight - .NET Code Modifying HTML
30. Silverlight - Using Isolated Storage Quotas
31. Silverlight - Calling JavaScript from .NET
32. Silverlight - Evaluating JavaScript from .NET Code
33. Silverlight - Handling HTML Events in .NET Code
34. Silverlight - Handling .NET Events in JavaScript
35. Silverlight - Calling .NET from JavaScript
36. Silverlight - Displaying a Custom Splash Screen
37. Silverlight - Passing Parameters from your Web Page
38. Silverlight - Loading Media at Runtime
39. Silverlight - Dynamically Loading Assemblies/Code
40. Silverlight - Reading/Writing XML
41. Silverlight - Multiple Threads with BackgroundWorker
42. Silverlight - Insert/Update/Delete with the DataGrid
43. Silverlight - Getting Started with the DataGrid
44. Silverlight - Embedding Custom Fonts

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 406 | 返回顶部

Applications = Code + Markup读书笔记(1)

This Article is Published by Live Writer。

1. 关于Application和Window的层次结构

Object
└─DispatcherObject (abstract)
    ├─Application
    └─DependencyObject
        └─Visual (abstract)
           └─UIElement
               └─FrameworkElement
                   └─Control
                       └─ContentControl
                           └─Window

2.如果没有显示的设置Window的宽或高,他们的值将始终是NaN

The Width and Height properties are initially undefined, and if your program never sets them, they remain undefined, which means they have values of NaN, the abbreviation immortalized by the IEEE (Institute of Electrical and Electronics Engineers, Inc.) floating-point standard for "not a number."

3.与设备无关单位(1/96inches),这一点需要与DPI进行区分

The units in which you specify all dimensions and locations in Windows Presentation Foundation are sometimes called device-independent pixels or logical pixels but it's probably best not to refer to pixels at all.

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 403 | 返回顶部

横穿马路被电视台抓住采访时要沉着应答

This Article is Published by Live Writer。

一天,在回家的路上,被一群拿着摄像机的家伙拦住了,   其中一个什么也没有拿的靓女说他们是XX报社的,要采访我。   采访开始后,那靓女问我:“刚才你是不是从马路中间的护栏上跳过来的?“我说是,没错。她问我知道那么做不对吗?知道不对为什么还要违反交通规则?  

我说为了节省时间,时间就是金钱就是生命,浪费我的时间就等于图我的财害我的命,   这是鲁迅先生说过的话。那靓女听我说完愣了半天,   然后才想起来问:难道就不知道那么做是很危险的吗?我说习惯就好了,这世界上哪有绝对安全的地方?地球是转动的,生命是运动的,一不留神谁都能玩完,睡觉都能活活把人睡死吃饭都能把人活活噎死,想通这些,跳个护栏还怕什么危险?她对我的回答很感意外,只是傻傻地站着,不知该再问我什么才好。于是我主动地伸手和她握握,很友善的说:“是实习生吧,没什么事我先走了。在又一次回家的路上,我又被一群拿着摄像机的家伙拦住了(烦),其中一个什么也没有拿的比原来那个靓女更靓的靓女说她们是XX报社的,要采访我。采访开始后,那靓 女问我:“刚才是不是从马路中间的护栏上跳过来的? “我说是,没错。她问我知道那么做不对吗?知道不对为什么还要违反交通规则?我说为了节省时间,时间就是金钱就是生命,浪费我的时间就等于图我的财害我的命,这是鲁迅先生说过的话。那靓女听我说完咯咯笑了半天,然后才想起来问:要是被车撞了你更得损失时间损失金钱甚至生命,难道你觉得那么做是很值得的吗?我说想开就好了,这世界上哪有绝对值得的事情?地球是转动的,生命是运动的,一不留神谁都能玩完, 美国游骑兵部队听过吧,NB吧,叫索马里民兵打的满街跑;人拜神社知道吧,无耻吧,就有人给他泼墨水;以色列杀巴勒斯坦人不当回事吧,就有人宁可挨子弹也要扔他一石头。没有什么事是稳赚不赔的,想通这些,跳个护栏还怕什么危险?有的人连万年唾骂都不怕了冒死要把台湾岛分出去,他们都不怕我为什么怕呢?她对我的回答很感意外,但是她的水平似乎要高一点  

她坚持问:“那些事情都是国家大事 你不认为用这些事情来证明你翻护栏正确是   很没有道理的么? ”  

我说,皮之不存,毛将焉附, 一般来说我们大礼不拘小节、大义不存小仁,一个人如果不翻护栏,他无非是个好市民,但一个人如果国家大事的对错都分不清楚,就非常可怕了,我宁可做一个为时间为事业为祖国而不惜生命的人,也不愿意做一个面对一道护栏苟且偷生的人,连小溪都不能渡过的树叶,如何横越海洋,连护栏都不跨过,能指望这样的人在战场上冒着敌人的炮火舍生忘死,冲锋陷阵么?  

她只是傻傻地站着,不知该再问我什么才好。于是我主动地伸手和她握握,   很友善的说:“你是和那个实习生一起参加工作的吧,没什么事我先走了。不用担心,日子长了就好了。”

from:笑口常开

Tags: DongPad

分类:Relax Bar | 固定链接 |评论: 0| 引用: 0 | 查看次数: 400 | 返回顶部
This Article is Published by Live Writer。

WPF 提供了一套性能分析工具,来帮助您分析应用程序的运行时行为,并确定可以应用的性能优化的类型。下表列出了 Windows SDK 工具 WPFPerf 中包括的五个性能分析工具:

Perforator(分析器)
用于分析呈现行为。Perfortor(分析器)是一种用于分析呈现行为的性能分析工具。Perfortor(分析器)主窗口显示了一组选项,您可以利用这些选项来分析应用程序各部分中非常具体的呈现行为。
使用 Perfortor(分析器)
若要使用 Perfortor(分析器),请启动您想要分析其呈现行为的 WPF 应用程序。启动了应用程序后,在 Perfortor(分析器)中单击“Refresh”(刷新)按钮。应用程序现在应出现在 WPF 应用程序的“分析器”(Perforator)列表框中。选择想要分析的应用程序和呈现选项。Perfortor(分析器)数据值(比如帧速率)将立即反映应用程序的呈现行为。

Visual Profiler(可视化探查器)
用于按可视化树中的元素分析 WPF 服务(如布局和事件处理)的使用。可视化探查器是一种性能工具,用于按可视化树中的元素分析 WPF 服务(如布局和事件处理)的使用。通过分析此工具的分析输出,可以确定应用程序中的哪些可视元素可能引起性能瓶颈。可视化探查器主窗口显示一组选项,您可以利用这些选项来指定要如何分析应用程序:

Update Interval(更新间隔)。 要在分析过程中使用的时间间隔。

Display Overlay(显示覆盖)。 显示覆盖选项允许您显示 CPU 资源使用量 — 暗红色的覆盖指示较大的 CPU 资源使用量。

可视化分析的值

使用可视化探查器
若要使用可视化探查器,请单击“Start Profiling”(开始分析)按钮,并选择“Launch”(启动)或“Attach”(附加)。为了使用“Attach”(附加)选项,WPFPerf 和所分析的应用程序都必须以管理访问权限运行。同样,覆盖功能处于禁用状态,因此可用于“Attach”(附加)选项的事件较少。“Launch”(启动)选项是推荐选项。

Working Set Analyzer(工作集分析器)
用于分析应用程序的工作集特征。
Working Set Analyzer(工作集分析器)是一种 WPF 性能分析工具,提供有关指定进程的内存使用量信息。利用此工具,您可以生成特定应用程序状态时的应用程序内存使用量信息的快照。

Event Trace(事件跟踪)
用于分析事件并生成事件日志文件。
Windows 事件跟踪 (ETW) 是一种高效的内核级别跟踪工具,它使您能够将内核或应用程序定义的事件记录到日志文件。您可以在实时或从日志文件中使用事件,并使用它们来调试应用程度或确定应用程序中何处发生了性能问题。WPF 事件跟踪分析工具使用 ETW 来记录事件。

ETW Trace Viewer(ETW 跟踪查看器)
以 WPF 用户界面的格式记录、显示和浏览 Windows 事件跟踪 (ETW) 日志文件。
Windows 事件跟踪 (ETW) 提供了一种机制,用于跟踪和记录用户模式应用程序引发的事件。ETW 在 Windows 操作系统中实现,为开发人员提供了一组快速、可靠而通用的事件跟踪功能。“Event Trace”(事件跟踪)工具允许您用特定于 WPF 的用户界面格式记录、显示和浏览 ETW 日志文件。


Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 557 | 返回顶部
This Article is Published by Live Writer。

It's finally here - the launch of the .NET Reference Source project.  This post (hopefully!) contains everything you need to know.  Over the past few weeks, we ran a pilot of this feature and collected lots of great data that helped us work through some issues and understand where people were likely to have problems.

First, though, if you have any problems, please make sure you've followed all of the steps exactly as described.  If you're still having problems, please check the FAQ/Troubleshooting section at the bottom.  If that doesn't work, post a comment below and I'll look into it.

BASIC SETUP

Note this functionality is not available on the Express versions of the Visual Studio 2008 products.

1) Install the Visual Studio 2008 QFE.  This Hotfix just updates a DLL that's part of the Visual Studio debugger that fetches the source files, more details on the download page.

UPDATE:  If you get an error installing the Hotfix , try inserting your VS 2008 DVD and then running the Hotfix EXE again.  We're looking into the root cause - it's related to having a prior version of VS 2008 (e.g. Beta 2) installed on the machine.  But this workaround should allow the Hotfix to install properly.

UPDATE (1/18): There were some problems with the QFE link above that have been addressed, sorry for the inconvenience, it's fixed now.

2) Start Visual Studio 2008 and bring up Tools > Options > Debugging > General.  If you are running under the Visual Basic Profile, you will need to check the box on the lower left of the Options Dialog marked "Show All Settings" before continuing (other profiles won't have this option).

Set the following two settings:

  • Turn OFF the "Enable Just My Code" setting
  • Turn ON the "Enable Source Server Support" setting

Your settings should be as below:

image

3) Next, bring up the "Symbols" Page and set the symbols download URL and a cache location.  Specifically, set the three settings below:

    • Set the symbol file location to be: http://referencesource.microsoft.com/symbols
    • Set a cache location.  Make sure this is a location that your account has read/write access to.  A good option for this is to place this path somewhere under your user hive (e.g. c:\users\sburke\symbols)
    • Enable the "Search the above locations only when symbols are loaded manually" option.

When you're finished, the settings should look like the image below:

image

Setup is done!  That's it, really!

DEBUGGING INTO FRAMEWORK SOURCE

For this simple example, we'll start with a blank C# Windows Application project, but it will work the same with a VB, Web, or WPF project.  To walk through this, go ahead and create that project.

Set a breakpoint in Form_Load:

image

Now run your project to hit that breakpoint and go to your Call Stack window (CTRL+ALT+C).  In the Call Stack, right click a frame that starts withSystem.Windows.Forms.dll, and choose "Load Symbols".  This will load the symbols for the System.Windows.Forms assembly, which are about 10 megabytes, so the speed of the download will vary according to your connection speed.  Note that Visual Studio may be unresponsive during this time.   However, this download is a one-time cost for each assembly.  The symbols (PDB) file will be cached on your machine, in the directory specified in the steps above.

Loading Symbols Manually

This will load the symbols for the DLL from the server, and you'll see some information in the status bar to reflect this.  Note that when this completes, the call frames will turn black and line numbers will be available.  Note you'll need to do the Right Click -> Load Symbols step each time you launch a debugging session (but, again, the symbols will now be cached locally so they won't have to download).  For more information on this, see the ADVANCED USERS section below.

image

You have now loaded the symbols for the Windows Forms DLL and can begin viewing the code.  You can view code in any way that you normally would in a debugging session.  In this case you can either Step In to the line of code above, or you can double-click one of the frames in the Call Stack Window.   For this case, we'll step in (F11).

The first time you step into code, we'll be presented with the EULA for accessing the source code.  Please take the time to read this EULA.  If you agree to the terms of the EULA, hit ACCEPT, and the source will then be downloaded.

That's it! You're now debugging .NET Framework Source!

Debugging Form.cs in Windows Forms

Now, for each assembly that you'd like to debug into just repeat the steps above (note you'll only see the EULA once, not for each file).

There are times when the Assembly you'd like to debug into isn't on the call stack, for example in the code below:

image

Before you step in to Graphics.DrawRectangle, you need to get the symbols for System.Drawing.Dll loaded.  To do this, we use the Modules Window(CTRL+ALT+U).  This lists all of the modules (DLLs) loaded by the debuggee.  Just find System.Drawing.DLL in this list, right click, and choose Load Symbols.

Load via Modules Window

Note that once a symbol file is loaded, the path to the symbol file shows up in the "Symbol File" column.

You can now step into the Graphics.DrawRectangle code above using F11!  In this case, note, you'll have to step through the PaintEventArgs.Graphics property code first.

ADVANCED USERS

Normally, each time you launch a debugging session, Visual Studio attempt to download symbols for each DLL that loads into the debuggee process.  As part of this process, it asks each path specified in the Debugging Symbols dialog for the corresponding PDB.  Some projects load a LOT of DLLs which won't have symbols available, so this process can significantly impact debugger startup time as this probing occurs.  It is mainly for this reason we've recommended manual symbol loading in the steps above; we don't want using this feature to degrade the debugging experience across-the-board.

There is, however, a way to allow automatic symbol loading (which avoids the "Load Symbols" step) in a way that minimizes performance impact.   This is for more advanced users because it requires regular trips back to this Debugging Symbols Dialog.  Note you can quickly get to this dialog by choosing the "Symbol Settings..." item on the right click menus pictured in steps above form the Call Stack or Modules windows.

The key is to get all of the symbols for a given project type downloaded and cached locally, then turn off the automatic symbol downloads.  This will prevent the pings at debugger startup as well.

To do this, configure your setup as above with the following difference: Uncheck the "Search from the above locations..." item on the dialog.

Now, launch your project in the debugger.  This will cause all of the symbols available for the DLLs in your process to be downloaded at on-demand as the DLLs are loaded into the process.  Depending on your connection speed, this could take a while (it's generally about 50MB of symbols), so it's a good idea to hit F5 then go do something else for a while.  Again, these symbols are cached so this is a one-time cost.  Visual Studio will likely be unresponsive during this download process.

image

Once that process has completed, stop the debugger, and UNCHECK the the Reference Source Server symbol location, and hit OK:

image

Now when you launch the debugger, symbols will load automatically and you'll be be able to step in and through call stacks normally.  Note if you switch to a different project type (that has different assemblies), or have assemblies that are loaded later by your project, you can just repeat these steps to get any assemblies you don't have cached locally).

FAQ/TROUBLESHOOTING
1) Which assemblies are currently available for symbol/source loading:
  • Mscorlib.DLL
  • System.DLL
  • System.Data.DLL
  • System.Drawing.DLL
  • System.Web.DLL
  • System.Web.Extensions.DLL
  • System.Windows.Forms.DLL
  • System.XML.DLL
  • WPF (UIAutomation*.dll, System.Windows.DLL, System.Printing.DLL, System.Speech.DLL, WindowsBase.DLL, WindowsFormsIntegration.DLL, Presentation*.dll, some others)
  • Microsoft.VisualBasic.DLL
2) When I choose "Load Symbols" I get an Open File dialog asking for the PDB.

This can be caused by one of four situations:

  • You didn't configure the symbol location URL properly from basic setup above.  Ensure it's http://referencesource.microsoft.com/symbols.
  • You chose a cache symbols directory that your user account doesn't have write permissions for.
  • You attempted to Load Symbols for a DLL that's not available in the list above
  • You have a different version of the .NET Framework on your machine - this can happen, for example, if you're running a Windows Server 2008 Beta.  To check this, go to the Modules Window in Visual Studio (CTRL+ALT+U) and ensure that the version number of your mscorlib.dll is 2.0.50727.1433, as below.  If not, make sure you install the RTM Version of the .NET Framework 3.5.

  • Check your "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE" (or wherever you installed VS) for a file called symsrv.no.  If that file exists, rename it to symsrv.yes, and restart Visual Studio.
3) When I try to open or step into a source code file, I get a dialog that says "Source is not available for this location" or I get an Open File dialog for the file.

First, see FAQ item (2) above to ensure the symbols for the DLL were loaded successfully.  You can verify this by looking in the Modules Window under the "Symbols Status" column.

If the Symbols Status is "Symbols loaded.", check the following.

  • If you have configured Microsoft Symbol Server in the past, you may have already downloaded symbols for this DLL that don't contain source information.  Try specifying a different cache path or deleting your existing cache path, and then repeating the Load Symbols command.   See FAQ #4 for more information on this.
  • Ensure you have checked the "Enable Source Server" item on the Tools -> Options -> Debugging -> General page
  • Ensure that your account has read/write access to your cache path
  • If you have _NT_SYMBOL_PATH set, it will override these settings.  Details here.
4) I also use Microsoft Symbol Server to download symbols.  What's the difference? Can these two programs co-exist?

Microsoft Symbol Server provides symbols without any source information in them.  That information has been removed (sometimes referred to as "stripped") before publishing.  The symbols provided on the Reference Source Server are full symbols with debugging information.

The key to using both is to have your Reference Source path above the Symbol Server Path so that those symbols are searched/found first.  As described in the ADVANCED USERS section above, you'll likely want to launch your debugger once with this configuration to get all the symbols downloaded, then uncheck both of these paths to avoid debugging launch slowdowns in the future.  Also note that this may conflict in the future as more DLLs are added to the Reference Source Project.  Meaning, if you've already downloaded the Symbol Server symbol, you'll need to delete that or change your cache path to get the Reference Source one (Visual Studio has no way of knowing which is which).

image

One final note here, if you have the Microsoft Symbol Server configured via _NT_SYMBOL_PATH, you'll need to add the Reference Source path above to that path as well - _NT_SYMBOL_PATH overrides the above settings.

5) Does this work with 64-bit?

Yes, we've also provided 64-bit versions of the PDBs.  Note some DLLs work on multiple architectures, so not all of them need a separate 64-bit PDB.

6) How do I set breakpoints in Framework code?

Visual Studio requires the code to exactly match what is expected by the PDB.  The source publishing process, however, makes some small updates to the code, such as pushing a standard copyright banner to the end of the source file.  This changes the signature (CRC) of the code file.  However, it's still easy to set a breakpoint.

Just set your breakpoint as normal (you'll see it fails with a little warning icon), then right click the breakpoint and choose "Location..."

image

Then check the "Allow Source to be Different" box, hit OK.

image

Now the breakpoint will set successfully.

If you find yourself doing this often, you can also disable source matching in general by disabling Tools->Options->Debugging: “Require source files to exactly match the original version.”

7) Why don't some features like "Go To Definition" work?

Browse database information is separate from symbol (PDB) information within the debugger, so that information is maintained by the project system when a project is compiled and is not present within the symbol files.  So, unfortunately, that ability is not available here.

8) Why are some member or local variables unavailable?  Why can't I step into certain functions or lines of code?

The .NET Framework bits that you have installed on your machine are “retail” bits, which means they are optimized for size and performance.  Part of this optimization process removes certain information from the process when it is no longer needed.  Debugging retail assemblies reflects this.  However, most debugging information is still present in the session, and setting breakpoints earlier in a function often allows it to be visible.   Another aspect of retail builds is that some small methods may be “inlined” which means you will not be able to step into them or set breakpoints in them.  But for the most part you can step and debug as normal.

9) Why does it take so long to download some source files?

Some source files are very large - nearly 1MB - and unfortunately many of these are the common ones to download.  However, most are significantly smaller and download quickly.  Source files must be downloaded each time you restart Visual Studio.  They are not persistently cached like symbols are.

10) Can I just download all of the code at once?

Not currently, but we are currently working on enabling this functionality in the future.

11) When I debug into VB code, for example in Microsoft.VisualBasic.dll, there is a C# style comment at the bottom, is this a bug?

Not really - we do run a post processing step when publishing the code and it adds a standard copyright banner at the bottom.  The processor, at this time, isn't able to support multiple comment formats.  Having it in a non-VB format doesn't affect the debugging functionality in any way.

12) I got to a source file and all that downloaded was a blank file?

This is something we've seen intermittently but have not been able to diagnose.  If you see this, usually the workaround is to just restart VS, which will force the file to reload.  If you observe this behavior, please use the "Email" link on the left to email me the name of the file that failed and about what time the failure occurred.

13) What happens if I download a Hotfix or a Service Pack?  Will I be able to get source for that?

We've built a system that allows us to publish any number of versions of source and symbols for a given product.  We haven't made any firm decisions on how often we'll publish source and are open to customer feedback on those issues.  For example, it's clear that publishing source for each Service Pack makes sense, but it's unclear if we'll be able to do so for each Hotfix.  Again, we're looking forward to feedback here.

In the meantime, also note that symbol files may no longer match a module if a framework DLL has been updated via a Hotfix. In those cases, the modules window will indicate that the symbols could not be downloaded for that module. Assuming a new symbol file was published, it can be downloaded and cached using “Load Symbols”.

14) Can I point a web browser at the symbols URL and download the symbols directly?

No, you'll get an HTTP 400 (Bad Request) response.

SUPPORT

If you have any other questions, please visit our new MSDN Forum on the topic: Reference Source Server Discussion.

Thanks!

from:Shawn Burke's Blog

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 576 | 返回顶部

新版.Net开发必备十大工具

This Article is Published by Live Writer。
Snippet Compiler

   Snippet Compiler是一个基于 Windows 的小型应用程序,你可以通过它来编写、编译和运行代码。如果你具有较小的代码段,并且你不想创建完整的 Visual Studio .NET项目(以及该项目附带的所有文件),则该工具会很有用。现在Snippet Compiler已经支持.NET Framework 3.5,最新版本为Snippet Compiler Live 2008 Ultimate Edition for Developers (Alpha)。

Microsoft Source Analysis for C#

   Microsoft Source Analysis for C#是一款C#(不支持VB.NET)代码规范检查工具,前身是微软内部代码规范检查和代码格式强制工具StyleCop,目的是帮助项目团队执行一系列常用的源代码格式规范,它会根据预定义的C#代码格式的最佳实践进行检查,与FxCop不同的是它直接对源代码进行检查,且并不提供灵活的规则设置,强制开发者使用相同的习惯进行C#代码的编写。

GhostDoc

   GhostDoc是Visual Studio的一个免费插件,可以帮助开发者生成比较完整规范的XML格式代码注释,如果你的代码遵循微软类库开发人员设计规范 ,由它自动产生的注释就已经完全可以很好地表达开发者创建的方法或者属性的意图,无需手工再进行修改。有了这些标准的XML注释,我们可以使用微软的文档工具Sandcastle生成专业级别的帮助文档。

Sandcastle

   Sandcastle是微软发布的一个帮助文档生成工具,它通过反射程序集中的源代码和添加代码到中的XML注释来创建专业级别的帮助文档。Sandcastle于2006年推出,它的面世也使得曾经列入.NET开发必备十大工具之一的文档生成工具NDoc的作者Kevin Downs在2006年7月宣告不再投入NDoc Open Source Project的开发。

Nunit

   NUnit 是为 .NET 框架生成的开放源代码单元测试框架。NUnit 使你可以用你喜欢的语言编写测试,从而测试应用程序的特定功能。当你首次编写代码时,单元测试是一种测试代码功能的很好方法,它还提供了一种对应用程序进行回归测试的方法。NUnit 应用程序提供了一个用于编写单元测试的框架,以及一个运行这些测试和查看结果的图形界面。

MyGeneration

作为.NET开发人员,手边有一款代码生成工具必不可少。旧版.NET开发必备十大工具中,曾经有非常著名的CodeSmith,不幸的是现在CodeSmith已经商业化,需要花钱购买;幸运的是我们又有一款免费并开源的代码生成工具选择MyGeneration,它的功能丝毫不亚于CodeSmith,完全基于模板引擎进行代码的生成。

Reflector for .NET

相信大名鼎鼎的Reflector for .NET大家都已经用过了,几年前它已经位于.NET开发必备十大工具榜,现在自然也不能例外。它是一个类浏览器和反编译器,可以分析程序集并向你展示它的所有秘密。使用Reflector for .NET可以浏览程序集的类和方法,可以分析由这些类和方法生成的 Microsoft 中间语言 (MSIL),并且可以反编译这些类和方法并查看 C# 或 Visual Basic.NET 中的等价类和方法。经过多年的发展,Reflector for .NET已经发展到了5.1版本,并且提供了相当丰富的插件,利用这些插件我们可以浏览Silverlight程序结构、浏览WPF资源文件、与TestDriven.net集成等。

The Regulator

   The Regulator能够使生成和测试正则表达式变得很容易,它允许你输入一个正则表达式以及一些针对其运行该表达式的输入。这样,在应用程序中实现该正则表达式之前,你便可以了解它将产生什么效果以及它将返回哪些种类的匹配项。另外它还提供了正则表达式库管理功能,在线更新正则表达式库,可以在RegexLib.com上搜索需要的正则表达式。

LINQPad

随着在.NET Framework 3.5中对于LINQ的支持,越来越多的开发者在开发中使用了LINQ to SQL,但是编写LINQ to SQL查询似乎又成了一件很麻烦的事情,好在我们还有LINQPad这个工具,用来编写LINQ查询,不仅仅是LINQ to SQL,同时它也支持LINQ to XML、LINQ to Objects,另外LINQPad是完全免费的且无需安装,只要下载它的可执行文件就可以了。

NAnt

   NAnt 是一个基于 .NET 的生成工具,与当前版本的 Visual Studio .NET 不同,它使得为你的项目创建生成过程变得非常容易。当你拥有大量从事单个项目的开发人员时,你不能依赖于从单个用户的座位进行生成。你也不希望必须定期手动生成该项目。你更愿意创建每天晚上运行的自动生成过程。NAnt 使你可以生成解决方案、复制文件、运行 NUnit 测试、发送电子邮件,等等。遗憾的是,NAnt 缺少漂亮的图形界面,但它的确具有可以指定应该在生成过程中完成哪些任务的控制台应用程序和 XML 文件。目前NAnt已经支持.NET Framework 3.5,它的最新版本是0.86 Beta 1。

转自:新版.Net开发必备十大工具

Tags: DongPad

分类:C# | 固定链接 |评论: 1| 引用: 0 | 查看次数: 367 | 返回顶部