Question

Out of curiosity. I'd like to know if its possible to step into (F11) a background worker during debugging. It usually just skips over to the next line of code. Is it a VS setting that needs to be changed? Is it just how its meant to be?

Any clarification would be much appreciated. Thanks.

Was it helpful?

Solution 2

It usually just skips over to the next line of code.

That's because the BackgroundWorker is being executed on a different thread, which has to be created and started first, and this takes some time. If you keep stepping, you will enter the worker at some point, but there's no telling when exactly.

Just put a breakpoint at the start of the worker code if you want to debug it.

OTHER TIPS

As the comment says, you just have to set a breakpoint for the first line of code in your background task. (Or: Debugger.Break().)

Also, I recommend you to get a look for Debug > Windows > Threads window, it's quite useful in multithread debugging cases.

Once the debugging is started, open the thread window mentioned in Sebestyén answer. When the desired thread is started, keep an eye in the column "Location" of the new row that appeared in the Thread window. Once it have the name of the thread you want, right-click it and select "Switch to Thread". This solved the problem of the debugger cursor keep going to other points of the code (other threads running, I suppose) while I was trying to debug a specific thread.

From Haggisatonal answer at Visual Studio 2015 Debug doesn't work in multithread application

disable the VS hosting process (Project -> Properties -> Debug -> Enable the Visual Studio hosting process)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top