0

I am reviewing some code where MTA threads are calling making a call to EnumThreadWindows with their thread ID and looking for a Window with a particular class name. This window is created by an STA COM object explicitly for the purpose of tying an MTA thread to a itself.

I'm sure this works great when there's a single STA object (and therefore only one window); however, in the scenario where there are 8 of these windows and because these are non-GUI MTA threads I am wondering how can these threads be associated with a specific window. We don't create these, they're part of a thread pool in Internet Explorer relating to asynchronous pluggable protocol handling.

Unless I'm missing some 'magic' I would think that the EnumThreadWindows call would result in all windows in the process being enumerated because the threads are non-GUI threads.

I've done some initial exploration of this; however, the scenario in which these operations happen in our code is fairly complicated and doesn't lend it self well to this.

Is the enumeration behavior of EnumThreadWindows explained in more detail than what we see in MSDN?

Hans
  • 83
  • 1
  • 8
  • 2
    That doesn't make any sense, it is not going to find any window with its own thread ID. It needs to use the TID of the *specific* STA thread to find a window back. Big code smell, a thread in the MTA needs to marshal an interface pointer instead. – Hans Passant Feb 26 '15 at 17:02
  • I think this code grew out of a desperation from not knowing how to get a 'random' IE download thread associated with an STA object created during ::SetSite. – Hans Feb 27 '15 at 18:33

0 Answers0