Tech Community Live: Windows edition
Jun 05 2024, 07:30 AM - 11:30 AM (PDT)
Microsoft Tech Community

FileSystemWatcher not working in Desktop Bridge app

Copper Contributor


I have a problem with FileSystemWatcher within a desktop bridge app. I asked for this issue already in the WPF forum in Microsoft answers, but from there I was referred to this forum here.


I have a WPF app that uses FileSystemWatcher for various directories to react to changes in the directories.

For example:

"C:\ProgramData\Microsoft\Windows\Start Menu"

"C:\Users\Egon\AppData\Roaming\Microsoft\Windows\Start Menu"

As long as I start the app directly as a WPF desktop app, I get all the events when there is a change in both directories.

However, if I add a package project to the solution and launch the app as a desktop bridge app via the package project, I only get events for the general Start Menu directory, but no more events for the Start Menu directory for the user. This is reproducible on Windows 10 (VS2017) and Windows 11 (VS2022) both with .NETFramework 4.8.


I have tested Win32 API versions for directory monitoring within a WPF app as normal desktop app and as desktop bridge app:


ReadDirectoryChangesW() without OVERLAPPED

ReadDirectoryChangesW() with OVERLAPPED and GetOverlappedResult()

FindFirstChangeNotificationW() with WaitForSingleObject()


In none of these variants do I get a signaled event. As a normal desktop app they all work fine, but as a desktop bridge app they keep hanging when I monitor the user's start menu directory.

Here, I have a zip file with the source code. Ensure, that the project 'PackageDirectoryWatcher2' is set as start project. Start this sample, then copy any file into directory

C:\Users<YourName>\AppData\Roaming\Microsoft\Windows\Start Menu\

or its sub directories.

In the app window you will see, that nothing happens, means that the FileSystemWatcher doesn't invoke an event.

Then close the app, set the project 'DirectoryWatcher2' as start project and start the app again. Now, if you copy any file into directory

C:\Users<YourName>\AppData\Roaming\Microsoft\Windows\Start Menu\

the app window shows the triggered events.


So this is the difference between 'normal desktop' and 'desktop bridge' in the app behavior.

Is there any way to get notified within a desktop bridge app about changes in the user's start menu directory?

0 Replies