
- #TIMERS.TIMER VS THREADING.TIMER VS FILEWATCHER CODE#
- #TIMERS.TIMER VS THREADING.TIMER VS FILEWATCHER FREE#
Single-threaded environment it executes on the UI thread. The component has no user interface and is designed for use in a
#TIMERS.TIMER VS THREADING.TIMER VS FILEWATCHER CODE#
(.NET Framework only), a Windows Forms component that fires an eventĪnd executes the code in one or more event sinks at regular intervals. Like the Ĭlass, this class is intended for use as a server-based or serviceĬomponent in a multithreaded environment it has no user interface and The callback method is defined when the timer is Which executes a single callback method on a thread pool thread at Or service component in a multithreaded environment it has no user The class is intended for use as a server-based Which fires an event and executes the code in one or more event sinksĪt regular intervals. Information from Microsoft about this (see Remarks on MSDN): I don't believe that there is a difference between the two as it pertains to how small your intervals can be. The specific difference appears to be that is geared towards multithreaded applications and is therefore thread-safe via its SynchronizationObject property, whereas is ironically not thread-safe out-of-the-box. NET Framework Class Library" - also available as a.
#TIMERS.TIMER VS THREADING.TIMER VS FILEWATCHER FREE#
Any users with a NAS should feel free to report on their results, as well.This article offers a fairly comprehensive explanation: Also, I wonder if the FileWatcher library can watch a NAS. If any users could report back on their success or failure, that would be appreciated. I suspect the last point probably applies to non-Windows computers as well. This opens up some possibilities for intra-network communications without the hassle of setting up Servers and Sockets.
If you have Windows computers A and B on the same network and A has a shared folder, visible from B, then a B4J program using this library running on B can watch that shared directory on A. Even then, the resource usage is quite low as the thread is only calling the events subs and then going back to its waiting mode. Only when an event is detected does the thread start running. On systems that support native file events (like Windows, but probably others as well), the watcher thread consumes essentially 0 CPU resources while it's waiting for events. Once the JVM is in its steady state phase, this library is really snappy. It was about 27 ms on average during the JVM warm-up phase and under 1 ms once the JVM was warmed up (a few seconds after program start). I timed the interval between a File.WriteString call and the _CreationDetected event that responded to that new file. On a Core i7 Windows machine, steady state event latency is under 1 ms. 'watcher thread ended, this application will close now. StopMessageLoop 'With the main message loop ended and the FileWatcher Log("WatchingTerminated") 'The FileWatcher can still be used, it just has to be started again. Sub fw_WatchingTerminated 'Logs the termination of the FileWatcher Log("ModificationDetected: " & FileName) 'Logs the modification of a file or folder Sub fw_ModificationDetected(FileName As String) Log("DeletionDetected: " & FileName) 'Logs the deletion of a file or folder Sub fw_DeletionDetected(FileName As String) Log("CreationDetected: " & FileName) 'Logs the creation of a new file or folder Sub fw_CreationDetected(FileName As String) Log("creation time: " & fw.GetCreationTime("C:\Test\test.txt")) 'Log the new creation time of file Log("creation time: " & fw.GetCreationTime("C:\Test\test.txt")) 'Log creation time of a fileįw.SetCreationTime("C:\Test\test.txt", DateTime.Now) 'Set the creation time to now T.Initialize("t", 60*1000) 'Stop file watching in 1 minuteįw.Initialize("fw") 'Initialize with the event nameįw.SetWatchList(Array as String(File.DirApp)) 'Set the current dir to be watched The watching is performed off the main thread however events are raised on the main thread. This might introduce a latency in receiving file change events and might consume more resources, though I haven't tested it on any such systems. On systems that don't have native file events, the library will poll the file system for changes, periodically. On Windows, this library performs quite well, using the system's native file events and consuming only a minuscule amount of system resources. Beware, some operating systems won't support all of those attributes. Additionally, this library enables you to get and set last access time, last modified time, creation time, read-only state and hiddenness of files. It allows you to set certain directories to be watched, raising events when files or folders within those directories are created, deleted or modified.
This library wraps many capabilities from the package and a few from the java.io.File package.