This section describes how to use the windbg tool to apply to Silverlight. Program For debugging, we can determine the invalid reference or event and release it to release the memory in time.
First, download the windbg tool. Install the tool.
Then we prepare a simple Silverlight application whose XAMLCodeAs follows:
< Usercontrol X: Class = " Sldbg. mainpage "
Xmlns = " Http://schemas.microsoft.com/winfx/2006/xaml/presentation "
Xmlns: x = " Http://schemas.microsoft.com/winfx/2006/xaml "
Xmlns: d = " Http://schemas.microsoft.com/expression/blend/2008 "
Xmlns: MC = " Http://schemas.openxmlformats.org/markup-compatibility/2006 "
MC: ignorable = " D "
D: designheight = " 300 " D: designwidth = " 400 " >
< Grid X: Name = " Layoutroot " Background = " White " >
< Button X: Name = " Btnclick " Width = " 70 " Height = " 40 " Content = " Click me " > </ Button >
</ Grid >
</ Usercontrol >
The XAML. CS file is as follows, and an event is bound:
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. net;
Using System. windows;
Using System. Windows. controls;
Using System. Windows. documents;
Using System. Windows. input;
Using System. Windows. Media;
Using System. Windows. Media. animation;
Using System. Windows. shapes;
Namespace Sldbg
{
Public Partial Class Mainpage: usercontrol
{
Public Mainpage ()
{
Initializecomponent ();
This . Btnclick. Click + = New Routedeventhandler (btnclick_click );
}
Void Btnclick_click ( Object Sender, routedeventargs E)
{
MessageBox. Show ( " 1111 " );
}
}
}
First, right-click the Server Load balancer instance named sldbg on the Web Side and open the newly installed windbg tool.
2. In the windbg tool, "file"-> "attach to process", select the currently running iexplorer program to be debugged on the open page.
(The process ID of the task manager can be determined based on the IE process ID ).
3. After attaching the process to be tracked to windbg, we must first introduce SOS. DLL for debugging, so in the windbg command input :. load c: \ Program Files \ microsoft Silverlight \ 4.0.50826.0 \ SOS. DLL
4. Run the following command :! Dumpheap-stat-type sldbg, start to debug the Silverlight application named sldbg, its interface is as follows:
Fifth, we can see that the memory address of XX object is bbbbbbbb, So we enter the following command :! Run dumpheap-MT bbbbbb to view the usage of the object, as shown in:
6. Run the following command :! If an exception is found during dumpheap-stat-type sldbg, run the command to check that the memory address is mmmmmm! PE Mmmm, you can view the specific error cause.
This example is written in vs2010 + Silverlight 4.0.