Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does FileSystemWatcher work on another computers directory?

Something intrigues me and I don't find any resource on this.

How can FileSystemWatcher know when a file on a computer "A" is created/removed/changed/renamed ?

I thought that this worked with polling, (the observer polls the server to check update), but after verifying the network activity with Wireshark I saw that polling was not used. Does the SMB protocol use a observable/observer pattern ?

In this case how the server can know when a client doesn't observe him anymore ?

What is the consequence when the network falls during an observation and comes back right after?

Using FileSystemWatcher on another computer seems too easy to be true...

like image 472
Nicolas Dorier Avatar asked Mar 09 '09 16:03

Nicolas Dorier


People also ask

Which of the following are types of changes that can be detected by the FileSystemWatcher?

The FileSystemWatcher lets you detect several types of changes in a directory or file, like the 'LastWrite' date and time, changes in the size of files or directories etc. It also helps you detect if a file or directory is deleted, renamed or created.

What are the guidelines to be followed to avoid missing events while using FileSystemWatcher?

Note that a FileSystemWatcher may miss an event when the buffer size is exceeded. To avoid missing events, follow these guidelines: Increase the buffer size by setting the InternalBufferSize property. Avoid watching files with long file names, because a long file name contributes to filling up the buffer.

Is FileSystemWatcher multithreaded?

Nope, filesystemwatchers run on their own thread.

What is the use of file watcher?

File Watcher is an IntelliJ IDEA tool that allows you to automatically run a command-line tool like compilers, formatters, or linters when you change or save a file in the IDE.


1 Answers

Using FileSystemWatcher on another computer seems too easy to be true...

It kinda is. The underlying API - ReadDirectoryChanges() - opens up a connection to the server, which is responsible for responding when something changes. If that connection gets dropped for some reason, or you bump up against the connection limit of the OS you're connecting to, then you don't get notifications.

I've found that it is more reliable to poll periodically (with some rather long interval), and use FileSystemWatcher only as a way of responding quickly to changes in between polls.

like image 57
Shog9 Avatar answered Oct 16 '22 17:10

Shog9