The sad implementation history of COM component categories and why it means you have to click twice to see your newly-installed taskbar toolbar

Raymond Chen

Raymond

COM component categories let a COM object registration declare what kind of object it implements. Programs that want to offer a list of “all objects which can do X” can ask the COM component category catalog¹ for all the objects that can to X, and it will give you the list.

Component categories are identifier by their category ID (standard abbreviation: CATID), and an an object declares that it supports a particular component category is to declare support for that category in its class registration.

Maybe you see the problem here.

This means that in order to find all the classes which support a category, you have to enumerate all the classes and check each one to see if it is marked as supporting your category. This might have been a reasonable design back in the day, but nowadays the registry has several thousand objects in it, and a linear sequential search isn’t really the best algorithm any more.

This query occurs every time you open the Toolbar menu from the taskbar, and stalling the UI thread for a few seconds makes baby message pump cry, so Explorer pulls a trick: It keeps a cache.²

When Explorer needs to fill in the Toolbar menu, it checks its cache, and if the cache is present, it uses the values from that cache, on the theory that users do not frequently add or remove toolbars, so it’s worth saving users a few seconds of thumb-twiddling every time they open the menu, even though it means that once or twice it shows stale information. After displaying the cached information, Explorer kicks off a background thread to go ask the catalog for the up-to-date information and update the cache for next time.

This means that if you just installed a new toolbar, it won’t show up the first time you open the Toolbar menu, because that menu is showing the old cached data. You have to open the Toolbar menu, then close it, and then wait a few seconds to let the background thread finish updating the cache, and then open the Toolbar menu again.

Sorry to make you open the menu twice. But it’s to save you a few seconds of waiting all the other times you open the menu.

Bonus chatter: “What about adding a new function like SHRefresh­Toolbar­Cache that a setup program can run in order to prepopulate the cache?” Well, that would help only for the user who ran the setup program. Other users still have the stale cache problem.

¹ Thankfully, the phrase “COM component category catalog” is not abbreviated CCCC or C4. The standard abbreviation is “ComCat catalog.”

² If you’ve been keeping score, this means that we have a “COM component category catalog cache”, so we’re up to C5. I’m starting to think somebody is naming these things funny on purpose.

0 comments

Comments are closed.