ccalboni ccalboni - 3 years ago 85
C# Question

Is there a way to stay on current document after a "break all" in Visual Studio?

Visual Studio opens source code on top of the stack when I "break all" while debugging; I want to keep the cursor on the document I'm currently working on, without any other document or window (e.g.: no symbols loaded) being opened.

Answer Source

There is a way to stay on the current document, but that requires creating a Visual Studio add-in and a new UI command in the Debug toolbar. Credits for this answer should actually also go to openshac, who posted a similar SO question and also gave a workaround in his OP by using a macro.

The implementation is fairly simple (it took me a few minutes to have it working). First, in the add-in project, modify the Exec method in the Connect.cs file like this:

public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
    handled = false;
    if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
        if(commandName == "BreakInCurrentDocument.Connect.BreakInCurrentDocument")

            // here's where the magic happens
            // ******************************
            var activeWindow = _applicationObject.ActiveWindow;
            if (_applicationObject.ActiveWindow != activeWindow)
            // ******************************

            handled = true;

After creating and registering the add-in, just:

  1. click TOOLS on the Visual Studio's menu
  2. Customize
  3. Commands
  4. Choose the "Toolbar" radio button
  5. Select "Debug"
  6. Add Command...
  7. From the "Addins" category, choose your custom add-in.

That's it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download