cano63
asked on
FileSystemWatcher and Timer enable
I having problem starting a timer from a FileSystemWatcher event,
I don't know what is happening but it don't start the timer in any way , I also try
Timer1.start but did not wok, the problem is in the FileSystemWatcher event, if i turn it on from a button it work fine.
I don't know what is happening but it don't start the timer in any way , I also try
Timer1.start but did not wok, the problem is in the FileSystemWatcher event, if i turn it on from a button it work fine.
Form load
watchfolder = New System.IO.FileSystemWatcher()
watchfolder.Path = C:\
AddHandler watchfolder.Created, AddressOf logchange
watchfolder.EnableRaisingEvents = True
Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
timer1.enable = true
End sub
Is the Timer enabled?
One note of caution, Filesystem watcher raises events multiple times sometimes. Create a textfile and see for your self.
One note of caution, Filesystem watcher raises events multiple times sometimes. Create a textfile and see for your self.
ASKER
I saw what you said about the multiple events, is there any other thing that i can use to monitor a directory
I dont think there is an alternative. You can maintain history of files processed.
Is the timer enabled? Is it working?
Is the timer enabled? Is it working?
ASKER
Yes it is enable, but is not working
How do you know its not working? Have you stepped through it? What's the interval?
ASKER
One second, i put a breakpoint inside the timer code
That is strange. Usually the reason is that the Timer's Enabled property is set to False by default. Does the timer event have Hanles clause with it?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
It works
If that is the case, then the problem is likely due to the separate-threaded nature of the "logchange" callback. You could maybe ask the form to invoke a method that would start the timer (this might be a bad solution because I know the FileSystemWatcher can fire many many events).
(Untested Code)
Open in new window
Another would be to declare a timer object as Shared and hopefully be able to start it from a different thread (without using the Forms designer). Let me know if you want help doing something like that.
Best of Luck.