Shenghe's Blog

我的照片
姓名:

I worked in Aspen Iechnology Inc. My work focus on InfoPlus.21

2009年6月25日星期四

Summary -- ItemsControl

Summary for ItemsControl

This is a summary for this article

http://www.drwpf.com/blog/Home/tabid/36/EntryId/13/Default.aspx

 

1, what is ItemsControl?

It is the base class of every native WPF control that presents a collection of items, including but not limited to the following:

ComboBox

Menu

ContextMenu

ListBox

ListView

TabControl

ToolBar

TreeView

 

2, Is a Panel an ItemsControl?

No.  The logical children of a panel are UIElements, whereas the logical children of an ItemsControl (its Items) can be any CLR objects.

So what is a panel?  The main role of a panel is to provide layout support for its children.  Although a panel does maintain a collection of child elements, it is not technically a WPF “control”…  That is, it does not derive from the Control base class and it does not support the WPF notion of templating.  Instead, it is a single element with a single purpose… namely, to size and position (a.k.a., measure and arrange) its children

 

 


This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email, and any attachments thereto, is strictly prohibited. If you receive this email in error please immediately notify the sender and permanently delete the original copy and any copy of any e-mail, and any printout thereof.

2009年6月24日星期三

Summary for Items Control -- DataTemplate

Summary for Items Control – DataTemplate

 

1, WPF Content Model

The controls that can contain a single item (single logical child of type Object) are called "content controls".  These controls derive from the ContentControl base class.  Controls that can contain a collection of items (many logical children of type Object) are called "items controls".  These controls derive from the ItemsControl base class. 

 

2, The ItemsControl Content Model

Primarily, it allows the logical children of an ItemsControl to be any CLR objects. 

WPF has conveniently inserted a TextBlock into the visual tree to display the string representation of the item data.  (Note that the TextBlock is part of the visual tree of elements, but it is not a member of the logical tree.  The visual tree consists solely of visual elements, whereas, the logical tree may consist of both visual and non-visual objects.)

3, What is a template

In WPF, a template is just a tree of visual elements (along with some resources and triggers) used to define the look (and often behaviors) of a member of the logical tree.  As it builds the element tree, the framework watches for controls and data items that have corresponding templates.  When such an element is encountered, the appropriate template is "inflated" into the actual visuals that represent the logical item and those visuals are inserted into the visual tree.

The ControlTemplate class is used to provide the visual representation for a control (like a ListBox). The DataTemplate class is used to provide the visual representation for a data item (like an item within the Items collection of a ListBox). 


This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email, and any attachments thereto, is strictly prohibited. If you receive this email in error please immediately notify the sender and permanently delete the original copy and any copy of any e-mail, and any printout thereof.

2009年6月17日星期三

Summary -- How to debug with SOS.dll in Visual Studio ?

This is a summary from the article http://beta.blogs.msdn.com/tess/archive/2007/10/19/net-finalizer-memory-leak-debugging-with-sos-dll-in-visual-studio.aspx

 

From this article, I learned how to use SOS in Visual Studio. SOS can be a great help for debugging managed application.

1,  Enable native debugging for the project

1.png

2, Use “break all” menu ( under Debug\Break all ) to break

 

3, Load SOS.dll by using “.load” command in immediate window

2.png

 

4, Use “!help” command in immediate window, you can find how many useful command are available in SOS

 

5, Some general commands in SOS, You can use “ !help XXX” to find out what the XXX command is used for.

!clrstack                                        

!dumpheap – stat                     

!eeheap   -gc  

!dumpstack

!threads

!dumpobj

!gcroot

!syncblk

!objsize

!pe

!finalizequeue

 

 

Very easy and very powerful!

 


This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email, and any attachments thereto, is strictly prohibited. If you receive this email in error please immediately notify the sender and permanently delete the original copy and any copy of any e-mail, and any printout thereof.

2009年6月16日星期二

Summary -- What shall I do when meet a app hang with low CPU?

What shall I do when meet a hang with low CPU? In general, this is because of locking.

This is a summary from this article http://blogs.msdn.com/tess/archive/2008/02/04/net-debugging-demos-lab-1-hang.aspx

 

1, get a memory dump by adplus when hang

            Adplus –hang –pn  w3wp.exe  -quiet

2, load sos

3, ~* kb 2000   --- to show the native stack

4, ~* !clrstack   --- to show the managed stack

5, !syncblk        --- to show the thread id that owning the lock

6, ~5s               --- to move the thread that owning the lock

7, kb 2000

8, !clrstack

 

 


This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email, and any attachments thereto, is strictly prohibited. If you receive this email in error please immediately notify the sender and permanently delete the original copy and any copy of any e-mail, and any printout thereof.

FW: Summary -- Dispose Pattern

 

From: Cao, Shenghe
Sent: 2009
617 10:51
To: Cao, Shenghe
Subject: Summary -- Dispose Pattern

 

1, CLR's Garbage Collector free you of managing the memory that are allocated in managed heap. But you need to clean up other native resource by yourself.

You can use the object's finalizer to ensure that the native resources hold by this object are released when they are not needed.

 

2, But GC does not run the finalizer deterministically, not deterministic time, not deterministic order. So you need disposable object that implement IDisposable interface. GC does not know this interface.

 

3, Your host class that hold resources implement IDisposable interface. The consumer call dispose to free the expensive resource as soon as they are not needed.

 

4, But if you host class hold native and managed resource( finalizable objects), you should not free managed resource in your finalizer because the order of running finializer is not deterministically. So you might free your resource which might be finalized prior to the host object that has been finalized. But in Dispose method, it is safe to free managed and native resource.

 

5, The code in finializer and Dispose method might be duplicated. But just a little different. So you should use Dispose pattern. The code like this:

 

public class DisposableClass : IDisposable

{

    ‾DisposableClass()

    {

        Dispose(false);

    }

 

    public void Dispose()

    {

        Dispose(true);

        GC.SuppressFinalize(this);

    }

 

    protected virtual void Dispose(bool disposing)

    {

        if (disposing)

        {

            // Clean up all managed resources( finializable objects )

        }

           

        // Clean up all native resources

    }

}

 

 

 


This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email, and any attachments thereto, is strictly prohibited. If you receive this email in error please immediately notify the sender and permanently delete the original copy and any copy of any e-mail, and any printout thereof.