views:

123

answers:

2

I wish to set a breakpoint on the System.Threading.SynchronizationContext::SetSynchronizationContext static method so I can find out when the synchronization context is being set.

However I can’t find how to set a breakpoint in a method I don’t have the source code to.

(This should be easy!, but when I try to set the breakpoint on a method from the breakpoints window it does recognise the method.)

+6  A: 

Click Debug, Windows, Breakpoints, click New, Break at function, enter System.Threading.SynchronizationContext.SetSynchronizationContext, and click OK.

It will give you a warning, which you should ignore. I tried it, and it does work.


Edit by Ian Ringrose

I also had to turn off the "Enable Just My Code" setting in the Debugging configuration.

Start Visual Studio 2008 and bring up Tools > Options > Debugging > General. If you are running under the Visual Basic Profile, you will need to check the box on the lower left of the Options Dialog marked "Show All Settings" before continuing (other profiles won't have this option). Set the following settings: Turn OFF the "Enable Just My Code" setting

SLaks
that is what I did in the first place, but when I run my application the breakpoint in show with a yellow warning sign and the tooltip says the breakpoint will not be hit as the symbols are not loaded.
Ian Ringrose
I'm not sure why that would happen. I just tried it myself, and it worked perfectly.
SLaks
thanks I have now got it working, see my edit to your answer
Ian Ringrose
+2  A: 

It is possible to debug the .NET framework classes. All you have to do, is setup VS.NET so that it is able to download the debug symbols for the .NET framework from one of Microsoft's servers.

You won't be able to set a breakpoint inside a .NET method though, but, you will be able to step into another method of the .NET framework, and while debugging, and once you've stepped into that method, (and VS.NET has opened the file that contains the SetSynchronizationContext method), you'll be able to set a breakpoint on that method.

For information on how to setup VS.NET so that you can debug the .NET framework, click here

Frederik Gheysels
+1 as the link let me work out the setting I had to turn on, however I did not need the debug symbols.
Ian Ringrose