FWIW, I think that when you use the FileSystemWatcher component, you're handing over control of the threads to the operating system. THe only issue you can control with regards to threading is the SynchronizingObject property, which allows you to specify a particular Windows Forms component (anything that inherits from Control) that basically tells the events raised by the FileSystemWatcher to run on the same thread as the owner of that component. This avoids thread switching issues (which can cause a WinForms app to roll over at runtime). If your event procedures for the FileSystemWatcher need to modify properties of a form (perhaps writing to the form), and you didn't drag the FileSystemWatcher component from the toolbox (in which case the designer sets the SynchronizingObject property for you, to the current form), you'll need to set this property in code. (Check the hidden region when you drag a FileSystemWatcher instance to the form--the designer adds:
Me.FileSystemWatcher1.SynchronizingObject = Me
to the code. If you create the instance in code, and don't set this property, and need to write to a WinForm from an event handler, you could have trouble unless you switch to the form's thread before doing so. That's what the SynchronizingObject property does.
This is the only issue I can think of where you can control threading behavior with this class, however! -- Ken |