How do I attach Visual Studio to a process that is not started yet?

前端 未结 8 1199
不思量自难忘°
不思量自难忘° 2020-12-02 07:41

I have .NET program that can\'t be run from Visual Studio for some reasons (Excel file created from an Excel 2010 template project) for which I need to debug startup events.

8条回答
  •  时光说笑
    2020-12-02 08:11

    You can show a MessageBox, this would block the application, then you attach or reattach the debugger to the process and click ok to continue:

    MessageBox.Show("Attach process to debugger and click ok!");
    

    you can add it to the Form constructor (if you use winforms), so this would be executed before anything else, except for the initialization of components:

    public MainForm()
    {
        InitializeComponent();
        MessageBox.Show("Attach process to debugger and click ok!");
    }
    

    When you finish your debugging, comment out that line.

提交回复
热议问题