views:

25

answers:

1

When testing a Windows Forms UI I shall often want to modify the code whilst it is running. Clicking on the "Break All" arrow does this for me, however Visual Studio always displays the Program.cs window and sets focus on the Application.Run() method, which kinda makes. However most of the time I have the code I want to edit right in front of me and having to close the Program.cs window is an annoyance and something I just don't want to do.

Is there an easy way to get the code to Break in the current window?

The only way I've found is to write a little macro that will pause the code, check if a new window has been created and, if so, close it. It's not ideal and it is rather rudimentary but it does the job. I've then just added a Toolbar command called "Break In Place" which sits in my Debug Toolbar. The code for the macro if anyone is interested is:

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module Break
    Sub BreakInPlace()
        Dim activeWindow As EnvDTE.Window
        activeWindow = DTE.ActiveWindow

        DTE.Debugger.Break(True)

        If Not activeWindow Is DTE.ActiveWindow Then
            DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo)
        End If
    End Sub
End Module
A: 

If you've multiple computers available (or possibly even Virtual machines) you could use a remote debugger.

ho1