How to stop stopwatch while debugging C # and vs2012

So, for some calculations, I have code that depends on stopwatch .

However, as soon as the stopwatch starts, it does not stop even during debugging, and this creates problems for me when I try to debug the code.

Is there any way to stop the stopwatch during debugging. I am using VS2012.

+4
source share
4 answers

No, you can’t. Since the stopwatch does not actually work, like a thread that can be paused and resumed. It just takes time at the start and time at stop and calculates the difference.

Maybe if you post your code or concept, we could find a way to solve your problem without a stopwatch?

+6
source

This is probably not what you hoped for, but you can temporarily do this:

 stopwatch.Stop(); Debugger.Break(); stopwatch.Start(); 

you can wrap it in #if DEBUG if you don’t want to worry about accidentally leaving it.

+2
source

You can use the following if you are using the Debug profile in VS2012:

 #if DEBUG sw.Stop(); #endif 
0
source

use System.Diagnostics.Debugger.Break(); for this.

Debugger.Break: If the debugger is not connected, the user is asked if they want to connect the debugger. If so, the debugger is running. If the debugger is connected, the debugger is signaled by the user breakpoint event, and the debugger pauses the process as if the debug point was deleted.

Hope this helps.

-1
source

Source: https://habr.com/ru/post/1482097/


All Articles