Gateway Script to monitor directory for new files

Hi,
I am new to most of this and so the minor aspects of implementation tend to go over my head. Like the OP, I want to utilize the WatchService to monitor a directory for new .csv files that are automatically generated by equipment. I have written project scripts that will parse and transfer the .csv to SQL but I want the Watcher to listen for new files and trigger that process. My questions are:

  1. For my understanding, this code instantiates a new variable of type FileWatcher in the Global scope. Upon construction, the init function is called automatically, which in turn initiates the Watcher’s listener loop. The listener function is called asynchronously so that it can safely run a continuous loop without preventing other processes. Is that accurate?

  2. If I put this code in a Gateway Startup Event Script, should I set the script to run on a dedicated thread? If so should I still call the Watcher loop asynchronously? In general, would this be a proper place to put this kind of script?

  3. If this script resides on the Gateway, is the Global scope shown here accessible from Clients? I had read that Memory Tags were the preferred method for scoping variables globally. (Globally scoped objects)

  4. Kind of a catch-all question: I need to allow users to register selected directories to the WatchService. After this code runs once in the Gateway, can Client scripts instantiate new FileWatcher variables, and pass directory paths to the constructor?

Thanks!