Debugging Preparation: Windows Applications
The Windows Application project template creates a traditional Windows application using C# or Visual Basic and the common language runtime. Debugging this type of application in Visual Studio is straightforward. For more information, see Creating a Windows Application Project.
To debug a C# or Visual Basic Windows application
- Open the project in Visual Studio.
- Choose Start from the Debug menu.
- Debug using the techniques discussed in Using the Debugger.
When you create a Windows Application project with the project template, Visual Studio automatically creates required settings for the Debug and Release configurations. If necessary, you can change these settings. For more information, see Debug and Release Configurations.
To change the default Debug configuration
- Set the Debug mode to Project (usually) or Program (if you do not have a Visual Studio project for the Windows application).
- Define the DEBUG and TRACE constants, which allow your application to use the Debug and Trace classes.
- Turn on Generate Debugging Information.
- Set the Output Path to bin\Debug\.
- In C#, set Optimize code to false. (Optimized code is harder to debug, because the generated instructions do not correspond directly to your source code. If you find your program has a bug that appears only in optimized code, you can turn this setting on, but remember that code shown in the Disassembly window is generated from optimized source that may not match what you see in your source windows. Other features, such as stepping, may not behave as expected.)
Another way to debug a Windows application is to start the application outside of Visual Studio and attach to it. If you attach to a C# or Visual Basic Windows application, make sure the Common Language Runtime check box is selected in the Attach to Process dialog box. For more information, see Attaching to a Running Program or Multiple Programs, Attach To Process Dialog Box, and Windows Forms.