views:

142

answers:

3

I have app that uses two threads: one thread for regular application work and another that does some background processing. When I debug my app and have a error message displayed I click pause to get to the line when this error ocurred.

But unfortunately I'm redirected to current line of the second background thread.

My question is: how to force VC# to go on pause to line executed by my main thread?

+2  A: 

What you can do is use the debugger to pause a particular thread. Open up the Threads window, right click on your background thread and select Pause. Then hit F5 to resume the application and since the background thread is paused, it should resume on your main thread. You can then step through your main thread uninhibitted by the background thread.

Don't forget to unpause the background thread though :).

EDIT

Hmm, it appears the Threads window is not available in Expression editions of Visual Studio (Reference). Leaving up as a CW incase someone comes across this answer with a non-express version of VS.

JaredPar
And how to open Threads window in C# Express?
tomaszs
A: 

there is a combobox where you can chose the current thread. If not, you may have to pull this option into the toolbar first.

codymanix
I can not find it, could you write more verbose how to get it?
tomaszs
A: 

I think you mean, "how do you switch the displayed thread while debugging"? I could be totally misreading the question, but I think it might have something to do with the Threads window (Debug->Windows->Threads). Gives you a list of running threads, and lets you switch between them, when you're breakpointed.

neminem
And how to open Threads window in C# Express? I can not breakpoint because I am doing it to find out where is the line that causes error to display.
tomaszs
Yeah, sorry. I've never used the express version, but a bit of googling would seem to indicate that you're correct, it's functionality you just can't get without the full VS. If you could, though, pausing when the error occurs would presumably also allow you to switch threads at that point, much like having a breakpoint.
neminem