Dumisani
Dumisani

Reputation: 3048

During debug, step into background worker/thread. Possible?

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.

Upvotes: 5

Views: 11535

Answers (4)

Somboon Srisuk
Somboon Srisuk

Reputation: 21

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)

Upvotes: 2

jcs
jcs

Reputation: 639

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.

Upvotes: 2

Rik
Rik

Reputation: 29243

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.

Upvotes: 2

user1694775
user1694775

Reputation:

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.

Upvotes: 6

Related Questions