FileSystemWatcher.WaitForChanged is blocking (synchronous). There is absolutely no need for an idle loop, especially because you are handling events. Note EnableRaisingEvents defaults to true. Therefore, all you have to do is add the component to a form. There is no idle loop. There is no threading because the component takes care of that.
I understand you are using a Console Application. Therefore, you can create the following loop. Again, no need for an idle loop. The component takes care of all the details.
Do
Dim i As WaitForChangedResult = Me.FileSystemWatcher1.WaitForChanged(WatcherChangeTypes.All, 1000)
Loop Until fCancel
[update] "Note EnableRaisingEvents defaults to true." As per the Microsoft source code, this is only true if the FileSystemWatcher component is dropped onto a designer. As shown below:
/// <internalonly/>
/// <devdoc>
/// </devdoc>
[Browsable(false)]
public override ISite Site {
get {
return base.Site;
}
set {
base.Site = value;
// set EnableRaisingEvents to true at design time so the user
// doesn't have to manually. We can't do this in
// the constructor because in code it should
// default to false.
if (Site != null && Site.DesignMode)
EnableRaisingEvents = true;
}
}
[update] Calling WaitForChanged
sets EnableRaisingEvents immediately before and after the System.Threading.Monitor.Wait
statements.