Einhugur FileSystemWatcher: Subclass fails on Windows console

I subclassed Einhugur’s FileSystemWatcher with a few methods and custom event handlers and use it successfully in a Mac console app. I wanted to do the same on Windows but found that the subclass will crash silently in its constructor. No errors in debugView, no exception handling is firing.

@Björn_Eiríksson : Is the class desktop only on Windows? I see no restriction, and my subclass is working flawlessly in a Windows desktop app.

The Windows API under to watch directory system changes is only Desktop.

Are several calls but this one is one of them:
FindNextChangeNotification function (fileapi.h) - Win32 apps | Microsoft Docs

I do not know why Windows has that limitation though…

When the plugin was originally made then I did not know Windows had this limitation. It does not seem to have made it into the docs yet though.

I guess the application needs to have Event loop, that might be their criteria, I have seen on the Web in some C++ apps then Console apps are creating Event loops to get it to work.

Oh I see, thank you.
Yikes, that was the part I had not tested before …
There is probably no easy way to add an event loop in a Xojo console app (with yours and Christian‘s plugins), right?

I do not know of a good way currently :frowning:

Thank you again.
I was happy I found your class – I once had created one using FSEventStream and WinDirectoryWatcher, both MBS, but found it hard to combine both with their very different event structure. I was not satisfied with what I got.

As Christian’s Windows class is console too, and its events are very close to yours, I think I’ll marry both major plugin developer’s watchers next …

Would a headless desktop app work?

Not in my case. It’s an app that watches and manipulates a variable number of folders which can be on remote drives too, which can sometimes cause delays and temporary stalls on a Mac‘s desktop. I use helpers to separate the GUI from functionality.
But don’t worry. Combining both plugins to a custom xplatform console savvy control was less than an hour and works great.

1 Like