January 12th, 2021

Why am I receiving SHCNE_UPDATEDIR notifications that my code never generates?

A customer had created a custom shell namespace, and they generated notifications for items in that namespace. Meanwhile, they also had code that listened for those notifications, and they found that sometimes the listener received SHCNE_UPDATE­DIR notifications, which is odd because their namespace never generates those notifications. So where did they come from?

The shell change notification system will sometimes coalesce notifications. It typically does this to avoid flooding the notification system.

The customer wanted to know if coalescing was more likely to happen when the notifications are generated at high frequency. They found that the behavior varied from system to system. Some of them were seeing the SHCNE_UPDATE­DIR, and others weren’t.

Yes, the rate of notification generation is a factor. If you quickly generate a hundred SHCNE_UPDATE­ITEM notifications for items all within the same folder, the shell change notification system is probably going to replace them all with a single SHCNE_UPDATE­DIR notification. The likelihood of coalescing also increases if the recipient is slow to process the notifications.

In such cases, the shell replaces the separate “item 1 changed”, “item 2 changed”, “item 3 changed” notifications with a single SHCNE_UPDATE­DIR, which means “There were changes to this folder.” This reduces the amount of notification traffic, reduces the memory needed to keep track of those notifications, and hopefully improves performance on the clients, since they can just refresh the whole folder instead of churning through hundreds of tiny little notifications.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • switchdesktopwithfade@hotmail.com

    When SHCNE_UPDATE­DIR arrives pointing to the 2-byte Desktop PIDL, does that mean the whole tree should be refreshed? I’ve seen it used ambiguously many times.

    Also there’s been this weird quirk where calling SHQueryRecycleBin() seems to fire SHCNE_UPDATE­DIR for the Recycle Bin. This can throw apps that monitor the Recycle Bin into an infinite loop.

  • cheong00

    Still remember when inotify on Linux silently drops excessive file change events if happens too frequently, causing trouble on use of FileSystemWatcher in Mono project.

    Now at least you get a grouped event.