Windows 8 application is debugging

Is there a way to check app.cs - the current state of debugging or deployment of the application?

Or the problem is that I want to exclude part of the code only when debugging the application.

0
source share
3 answers

You can simply use the #if DEBUG directive like this

 #if DEBUG //code here only executes in debug #endif 

So, if you need some code that works in DEBUG, and another that is in RELEASE, you do it like this:

 #if DEBUG //code here only executes in debug #else //code here only executes in release #endif 

And as DAKL explained, you can also use a conditional attribute.

+5
source

You can use [ConditionalAttribute ("DEBUG")] for this.

If you want the method to run only in debug mode, you can do the following:

 [ConditionalAttribute("DEBUG")] public void WriteOnlyInDebug(string message) { Console.WriteLine(message); } 

This method is called only in debug mode. The method and all calls to it are deleted from the binary file when creating the application in release mode.

+3
source

Other answers will tell you how to check at runtime if your application is compiled as a Debug assembly. If you want to see if Visual Studio (or any other debugger) is connected and is debugging your application, you can use System.Diagnostics.Debugger.IsAttached .

+1
source

All Articles