Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread.Sleep() stealing debuggers focus

Currently I have a background thread that does some periodic heavy data management. Because it only needs to run its process every few hundred milliseconds I call Thread.Sleep() at the end of the process and it then goes back to the top of the loop and repeats.

This is all working perfectly and doesn't cause any grief or performance issues for the rest of the software. The only thing that does bug me though is that when I break the debugger instead of going to my main threads current location, it gets stolen by the Thread.Sleep() and takes me there instead.

Is there any way that I can disable the debugger from stopping on that line, or is there an alternative to putting the Thread to sleep?

Thanks in advance!

like image 801
Craig White Avatar asked Nov 05 '22 09:11

Craig White


1 Answers

One thing you could try is to put the Thread.Sleep() in a method and add the DebuggerStepThrough on it.

You can also just "freeze" the you don't want to "steal focus" from Threads window (Debug -> Windows -> Threads). Also remember to unfreeze them when you're done

As an aside using a Timer (there are two) or a AutoReset Event is preferred to using Thread.Sleep() See Is Sleep() evil?

like image 174
Conrad Frix Avatar answered Nov 12 '22 17:11

Conrad Frix