WaitForChanged in a loop not firing after first call
Cheers! I am working with .net 4.0 and writing a vb.net console
application. The application has to monitor a folder and do something
every time a new file is saved into it
It always works the first go around, but subseqent go-rounds seem to fail,
and i can not figure out why. To test it i have a bunch of test images in
a test folder that i copy over 1 at a time to the capture folder, wait for
it process, and then try to drop another one in there.
The code is as follows:
Public Sub FileChanges()
Dim result As System.IO.WaitForChangedResult
watchfolder = New System.IO.FileSystemWatcher()
watchfolder.Path = My.Settings.WATCHDIR.ToString()
Console.WriteLine("Application Running, Waiting for a file")
result =
watchfolder.WaitForChanged(System.IO.WatcherChangeTypes.Created)
Console.WriteLine("Filechange Detected")
Dim fileName As String = My.Settings.WATCHDIR.ToString() &
result.Name.ToString()
End Sub
sub main()
Do
system.threading.thread.sleep(5000)
FileChanges()
Loop
End Sub
Any thoughts? Any better way in a console application to wait until a file
is created and then do something?
No comments:
Post a Comment