Debugging Multiple Programs
With the Visual Studio debugger, you can debug programs running in multiple processes. You can think of a process as an instance of a program running in its own memory space with its own object code, data, and resources. When you start a program by launching an EXE, for example, the system scheduler creates a new process for that program. If you launch multiple instances of the program, it creates multiple processes. The operating system creates other processes automatically, for its own purposes.
Here are some considerations and instructions for debugging multiple programs:
- Script Applications
- Techniques for Debugging Multiple Processes
- Starting Additional Projects
- Switching Between Running Projects
- Stopping the Current Process
Some programs, such as script applications, do not have their own processes. These programs are hosted by another application, such as Internet Explorer or Internet Information Services, and run in the host's process. To debug such a program, you must debug the host process. Usually, this involves attaching to the host process. For more information, see Debugging Script and Web Applications.
In Visual Studio .NET, you can debug multiple processes within a Visual Studio solution. In this case, each process is created by a separate project within the solution, so you can think of this as debugging multiple projects. You can do this by setting multiple startup projects, or you can start debugging one project and then start additional projects from Solution Explorer. For more information on multiple projects, see Choosing the Startup Project.
Visual Studio .NET also gives you the power to debug processes that are started outside of Visual Studio. To do this, you must start Visual Studio and attach to a running process. You can simultaneously debug processes started inside and outside of Visual Studio. Start a process in Visual Studio by running a project and then attach to an outside process. For more information, see Attaching to a Running Program or Multiple Programs.
You can debug multiple processes even if the processes are running code written in different languages. For example, you can simultaneously debug one process containing code written in C++ and a second process containing code written in Visual Basic, or a combination of Visual Basic and C++, or a combination of Visual Basic and C#. Mixed language debugging is generally transparent, as long as the languages are supported by the Visual Studio debugger.
To start one project when another is already running, both projects must be in the same solution. You can use Solution Explorer to start the additional project or projects:
To start a project in Solution Explorer
- In Solution Explorer, select the project you want to start debugging.
- Right-click the project name or icon.
- From the shortcut menu, choose Debug and click Start new instance.
When you are debugging two or more projects in a solution, you can switch between them in either of two ways:
To switch between projects while debugging
- On the Debug Location toolbar, select the program you want to switch to from the Program list box.
To display the Debug Location toolbar
- From the Tools menu, choose Customize.
- In the Property dialog box, choose the Toolbars tab and select Location.
- Click OK.
Switching to a project makes it the current process for debugging purposes. Any command you select from the Debug menu (such as Break or Continue) will affect the current process as well as the other processes running under control of the debugger.
To stop the current process only
- From the Tools menu, choose Options.
- In the Options dialog box, open the Debugging folder and choose the General category.
- Select In break mode, only stop execution of the current process.