Share via


.NET Framework Sample Application

You will first examine a small, component-based Windows Forms application using the GUI-based Microsoft CLR Debugger (DbgClr.exe) that is included with the .NET Framework SDK. The Visual C# and Visual Basic .NET code included here is a modified version of the Windows Forms–based Calculator sample that is used in other .NET Framework tutorials. The modified Calculator sample demonstrates how to write an application that allows debugging in two ways: by enabling the gathering of debugging and trace information, and by displaying an Assert dialog box when a condition occurs. The sample application also introduces some rather pointless code that the optimizer will remove.

**Note   **Where only Visual C# code is shown for a particular statement, the Visual Basic .NET equivalent can be obtained by omitting the trailing semicolon.

The application uses three source code files in two assemblies. Calc.exe is built from Calc.cs or Calc.vb, which contains the application entry point and the Windows Forms–related code, and from Parser.cs or Parser.vb, which contains code to parse the formula. A separate assembly in the \math subdirectory handles the arithmetic that depends on which calculator-operation button is clicked.

When compiled and run, the sample application produces an integer calculator that looks like the following figure.

Building the Sample

Before debugging this application, it is first necessary to compile the applications and components by running buildall.bat, located in the tutorial's \Calc subdirectory, or by running either build.bat, located in the tutorial's \Calc\CS and \Calc\VB subdirectories. It is important to note that to debug programs and components with DbgClr, you must first compile them with symbolic information using the /debug switch, as shown on the following command lines.

cd math
csc /target:library /debug+ /d:TRACE math.cs
cd..
csc /target:module /debug+ /d:TRACE Parser.cs
csc /target:winexe /debug+ 
   /addmodule:parser.netmodule /r:System.Windows.Forms.dll 
   /r:System.Drawing.dll /r:System.dll /r:math\math.dll 
   /d:TRACE Calc.cs

See Also

Debugging the .NET Framework Sample Application | Breaking into the Debugger | Trace and Debug Classes | Debugging and Optimization | The Microsoft CLR Debugger | Debugging ASP.NET Web Applications | Appendix A: For Additional Information | Appendix B: Runtime Debugger (CorDbg.exe)