Back to Basic : Difference between Start Debugging & Start without Debugging in Visual Studio

Back to Basic : Difference between Start Debugging & Start without Debugging in Visual Studio

In this post we are going to talk about yet another very basic, simple topic but seems confusing among many beginners – ‘Start Debugging  (F5) ’ vs. ‘Start without Debugging (Ctrl + F5)’.  In Visual Studio, we have seen these two menu items one after other under the Debug menu. There are lot of confusion around ‘when to use what’ or even ‘why we have two different option for debugging’ . Let’s try to simplify it over here.

StartDebugging

Start Debugging :

When you select this option (press F5 ) to run the application, Visual Studio loads all required symbols, “attaches the debugger” and then launches the application.  You should be able to see the assembly loading from the “Debug –> Windows –> Output”’ window.

image

With this option selected…

  • You can pause the execution of application by breakpoints
  • step through the code
  • Inspect elements
  • take advantages of all available debugging tools such as Watch Window, Data Tips and Diagnostic Tools etc.

Related Post : Tips and Trick on Breakpoints in Visual Studio

In short everything you want to do during the debugging of the application; you can achieve it with using “Start Debugging (F5)” option.

image

Related Post :  How to get list of attached processes in Visual Studio while debugging ?

In case, you want to check out the list of attached process during debugging, navigate to Debug –> Windows –> Process

image

10 Effective Debugging Tips for .NET Developer

Also once the debugger is attached / breakpoints hit you should be able to control the execution by pausing , stopping or by detaching the breakpoint.

Start without Debugging :

When you select this option (press Ctrl  + F5 ) to run the application, Visual Studio will launch your application without loading the symbols and attaching the Debugger.

In this case

  • if you have any breakpoint within the code, application won’t pause
  • you can’t step through the code.

So, this is just run your application in Debug mode with out having debugger attached with it.

Use “Run To Cursor” and save time while debugging

Quick Example with a Code Snippet:

The Debugger class, provides few set of API’s to enable the communication with debugger. Debugger.IsAttached   indicates whether a debugger is attached to the process or not.  let’s have a look and see how this work in both the cases.

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Debugger Attached :{0}", Debugger.IsAttached);
}
}

Run the app with both debugging option  – F5  & Ctrl + F5

debuggingVswithoutdebugging

As you can see from the above screen shots, the out of the example is differ in both the cases , as Debugger only gets attached when we select “Start Debugging (F5)” option.

Well, last but not the least, don’t get confused with below #pragma compilation in this context. Consider you have following statement …

#if DEBUG
Console.WriteLine("Sample Statement....");
#endif

In both the cases, the above code will execute and provide the same output,  because you are still running your application in Debug mode.

So, when you want to dig inside your code, step through, finding out issues and want to leverage all debugging tools you must go for F5 / Start with Debugging Option.

When you don’t want any step though your code, no breakpoints hit choose the other option… In that case you can use the “Start without Debugging (Ctrl+ F5)”.  Think about it,  you don’t need to remove / delete your existing  break points.. just run and do a quick test.. and when you want to dig inside, again use F5.

Hope this was useful !

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

One Comment to “Back to Basic : Difference between Start Debugging & Start without Debugging in Visual Studio”

Comments are closed.