This project has moved and is read-only. For the latest updates, please go here.

Snooping on a different thread

Apr 1, 2011 at 6:48 AM

My application uses different threads for different windows, and when I Snoop the application, if I attempt to select a window on a different thread, I get an InvalidOperationException "The calling thread cannot access this object because a different thread owns it." .

Is there a way to Snoop on a different thread? or a different way to get Snoop to start on that window's thread?


Apr 1, 2011 at 2:30 PM

Is your issue the same as If you could look into it and let me know ...

Maciek Rakowski has submitted a patch for this issue ... that I haven't had a chance to evaluate yet ... but if it is the same issue, you might want to try and download the patch and try it out yourself.

Apr 17, 2011 at 10:26 PM

This is essentially what I am seeing. I'll see about the patch...

Apr 18, 2011 at 3:03 PM

Interesting ... let me know what you find out ...

Apr 20, 2011 at 7:56 AM
Edited Apr 20, 2011 at 6:38 PM


There are a couple ways to run the patch. One way is to go to the patch website (, and download the entire 2.6 solution for the patch related to work item 6334. However, when I ran this on Windows 7 I needed to run Visual Studio as administrator. You may need to reload all the non-install projects.

If you don't want to compile the solution, and your application is built on the .NET 4.0 framework, you can run the patch out of the box. Simply download the patch and run the Snoop.exe program located in the binaries directory. Make sure you're running Snoop as administrator. The patch contains only the binaries to snoop .NET 4.0 applications.

If your application is built on the .NET 3.5 framework, you'll need to merge the binaries in the patch with those on your machine. Make a backup of the snoop.exe program, and replace it with the one in the patch. Here are the steps I had in mind:

  1. Download the patch ( for work item 6334.
  2. Extract the zipped items somewhere.
  3. Go to your snoop directory on your machine (usually "C:\Program Files (x86)\Snoop" on Windows 7).
  4. Make a backup of the Snoop.exe program on your machine (in the directory in step 3).
  5. Replace the Snoop.exe file on your machine (usually in the directory "C:\Program Files (x86)\Snoop") with the "\binaries\Snoop.exe" file in the patch.
  6. Try snooping.

See if this patch solves the problem of snooping on a different dispatcher thread.

Sep 5, 2011 at 9:15 AM

I tried the instructions above (.NET 4 on Win7) and ran Snoop, and I still encounter "The calling thread cannot access this object because a different thread owns it."

Sep 5, 2011 at 1:23 PM

The above fix has been integrated into the latest Snoop 2.7.0 release. Try installing that and seeing if you still get that error.

If you do, download the latest source code, build it ... and see if you can get us a stack of where the crash is coming from.

Note, to debug Snoop ... you actually attach to the process you are trying to Snoop ... not Snoop itself ... since Snoop injects itself into the Snooped process.

Let me know how it goes!

Sep 5, 2011 at 8:23 PM

While I was able to snoop the new threads, when I went back to the main thread using CTRL SHIFT click, I got a threading error once, but now I am not seeing this error.

Sep 7, 2011 at 3:11 AM
thenonhacker wrote:

I tried the instructions above (.NET 4 on Win7) and ran Snoop, and I still encounter "The calling thread cannot access this object because a different thread owns it."


Have you gotten a chance to test with the latest build? And if so, did it fix the problem?

Nov 18, 2011 at 6:56 PM


I've tested it with 2.7.0 release version (revision 69858 - all line numbers below are from that revision). Still the same error.

I debugged it, the exception occurs at

    Snoop.exe!Snoop.SnoopUI.FindRoot() Line 648 + 0x3b bytes    C#
    Snoop.exe!Snoop.SnoopUI.Inspect() Line 330 + 0xa bytes    C#
    Snoop.exe!Snoop.SnoopUI.GoBabyGo() Line 111 + 0x10 bytes    C#

The problem is that this stack trace (actually, call to Inspect on second line) occurs before checking if Snoop needs multithreaded mode (which is at lines 125-161, right after call to Inspect). FindRoot (first line on stack trace) depends on the fact that SnoopModes.MultipleDispatcherMode already correctly determined. Thus said, if I add line

SnoopModes.MultipleDispatcherMode = true;

at the beginning of GoBabyGo() thus effectively hardcoding it - FindRoot() doesn't throw (it is still warns user about absence of root visual in my case, but returns without exception) and snooping works - i.e. dialog about multithreaded UI appears and afterwards everything seems working.

Nov 18, 2011 at 7:17 PM
Edited Nov 18, 2011 at 7:18 PM

<oops, my bad. This message should be deteled :) >

Nov 18, 2011 at 8:32 PM


First off, thank you for bringing this to our attention. We want more people to let us know when they experience problems.

I'd like to fix this issue. Is there any way you can send or upload a test application that reproduces this issue? I'll look at it over the weekend (since my job doesn't like me working on non-work related stuff).




Nov 18, 2011 at 8:46 PM

Unfortunalety we have a proprietary framework here, so I can't share working example. In our concrete case the simplest fix that I did (and checked it works of course) is to refactor lines 125-161 to 'private static void DetermineMultipleDispatcherMode(Dispatcher defaultDispatcher)' method and call it just before snoop.Inspect() call at line 111 instead of end of GoBabyGo() method.


And due to specifics of our framework - main UI thread doesn't have any visuals, thus FindRoot() warns about 'Can't find a current application or a PresentationSource root visual!'. It is correct message, but not very useful because other UI threads do have visuals. So that after warning message Snoop window is opened and working (didn't tested extensively, but visual tree walking is ok).

Nov 24, 2011 at 9:23 AM

Hi idanilov,

I looked into the issue further, and made a fix very similar to what you suggested. I have the latest version checked in, so if you get a chance, please test it to make sure it fixes the problem. I made a simple test application that does what you said (no Visuals on the main UI thread), but I'm not sure how close it is to the one you're using at work. If I get a chance, I'll upload the test harness to see if it's the same approach you're using.

Thank you for taking the time to give us valuable feedback, and thank you for your contribution.


Nov 24, 2011 at 3:37 PM

Hi Maciek,


Thanks for your work! This version works for us. I noticed though minor issue. When you're clicking 'Snoop' button for the first time - everything goes as it should. But if you'll close snoop window that appeared and click 'Snoop' button again on the same application - it warns about no root visuals again. I suppose it is because on the second call SnoopModes.MultipleDispatcherMode is already true, so logic takes another branch in the FindRoot() method at line 689.


Nevertheless, thank you for the quick resolve of blocker issue and for implementation of multithreaded UI snooping logic in the first place. :)



Ivan Danilov