Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

FileSystemWatcher  and Timer enable

Posted on 2011-10-10
10
Medium Priority
?
326 Views
Last Modified: 2012-06-21
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.

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

Open in new window

0
Comment
Question by:cano63
  • 5
  • 4
10 Comments
 
LVL 7

Expert Comment

by:vbigham
ID: 36943471
I am assuming that this is a System.Windows.Forms.Timer and that its declaration is in the visual form designer is that about right?

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)
 
Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
    If MyForm.InvokeRequired Then
        MyForm.Invoke(AddressOf StartTimer)
    End If
End sub

Private Sub StartTimer()
    timer1.Start()
End Sub

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.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36944193
Is the Timer enabled?

One note of caution, Filesystem watcher raises events multiple times sometimes. Create a textfile and see for your self.
0
 
LVL 1

Author Comment

by:cano63
ID: 36945065
I saw what you said about the multiple events, is there any other thing that i can use to monitor a directory
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36945113
I dont think there is an alternative. You can maintain history of files processed.

Is the timer enabled? Is it working?
0
 
LVL 1

Author Comment

by:cano63
ID: 36945295
Yes it is enable, but is not working
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36945466
How do you know its not working? Have you stepped through it? What's the interval?
0
 
LVL 1

Author Comment

by:cano63
ID: 36945745
One second, i put a breakpoint inside the timer code
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36947512
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?
0
 
LVL 1

Accepted Solution

by:
cano63 earned 0 total points
ID: 36956124
Finaly I did the follow:

I configure the timer by defautl to be enable and create my code inside and if condition in the timer, this condition will execute if a boolena variable turn true. Then from the watcher sub i change the value of the variable to true or false
0
 
LVL 1

Author Closing Comment

by:cano63
ID: 37049231
It works
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question