Reputation: 323
I would like to know if there is any command or tool that can be used to start a process and then pause it immediately.
I need this function so that I can have time to attach a debugger to it. I have tried visual studio's /debugexe feature, but the behavior of the program seemed changed. So I need to find other way to attach it and debug.
Thank you.
Upvotes: 6
Views: 2377
Reputation: 21
In your main routine insert the line:
System.Diagnostics.Debugger.Launch();
Compile in debug mode. Run your program and it will break and prompt you to attach a debugger. If you have studio open it will ask if you want to use it to debug.
Upvotes: 2
Reputation: 32037
You can also add a call to
System.Diagnostics.Debugger.Break();
in the code. It will suspend the program and then ask you to choose the debugger you want to use. You can then attach to a running Visual Studio instance. If you're already running from a debugger, it will simply break as if it would have hit a breakpoint.
Upvotes: 0
Reputation: 76531
How about adding a Sleep() call as the very first statement.
Upvotes: 0
Reputation: 170489
You can use CreateProcess() with CREATE_SUSPENDED flag. This will start the process with the main thread suspended. Then you call ResumeThread() after having attached.
Upvotes: 5