Thread and dll and FileSystemWatcher

  • Thread starter Thread starter Nicolas
  • Start date Start date
N

Nicolas

Doesn't run properly.
I made one dll which monitor file and send back an event for status on
changes. I use the IO.FileSystemWatcher

From the window form I want to check 5 txt file in particular
(fi_1.txt,fi_2.txt,fi_3.txt,fi_4.txt,fi_5.txt) of course not residing on the
same directory or computer.
The idea was to do the following but It doesn't work that well. For only one
file is file it's perfect. But after, it is not clear for me, So I may need
help there.
Dim i As Integer = 0
Dim WithEvents ed_checkFile As ED_myDll_Interface

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
i += 1
Dim t As New Threading.Thread(AddressOf setTHREAD1)
obj.Add(t)
t.Start()
End Sub

Sub setTHREAD1()
Dim path As String = "D:\Development2\TEST"
Dim file As String = "fi_" & i & ".txt"
checkFile = New myDll(path, file)
End Sub

Private Sub ed_checkFile_Command(ByVal Command As myDll.Command) Handles
ed_checkFile.Command
Me.Label1.Text = "Command:" & Command.Code & " --- Type" &
Command.Type.ToString
End Sub

Is there a nicest way to monitor multiple specific file as the same time?

Thank you
 
My advice is to keep it simple.
1) You need a systemfilewatcher for every drive or folder unless you want to
watch all sub directories under a top level folder.
2) Set the filter to "*.txt" and then check the filename in the trapped event.
3) Don't do anything that you don't have to do in the event. If you need to
record the filename, write a text file on the same drive that you are
monitoring instead of writing to database. If you have to write to database,
do it in another program or thread that is reading the text file. This way
you minimize the time that you spend in the event and you know that it will
be successful as long as the drive you are monitoring is up. Just make sure
that you don't monitor the folder in which you are writing the text file.

Take a look at these articles

http://www.knowdotnet.com/articles/filewatcherservice.html
http://www.knowdotnet.com/forums/post.asp?method=ReplyQuote&REPLY_ID=318&TOPIC_ID=245&FORUM_ID=9

HTH
(e-mail address removed)
Add-ins, free code, hundreds of articles.
Try our latest time saving tool, Visual Class Organizer, free for 30 days.

http://www.knowdotnet.com/articles/VisualOrganizerProductHome.html
 
Back
Top