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

前端 未结 8 1172
不思量自难忘°
不思量自难忘° 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:15

    One little solution that might suit many people.

    • in the first line of code that the exe will run, add this command

      System.Threading.Thread.Sleep(20000)

    That will make the exe sleep for 20 seconds before it starts processing anything. Then you have 20 seconds to attach to the process, which can be done quickly with ctrl+alt+p, then find the process, then enter to attach.

    Not much of an answer but worked a treat for me :--)

提交回复
热议问题