Silverlight utility tip series: 45. Use windbg in Silverlight to debug applications and view exceptions

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.