473,396 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

FileSystemWatcher array WithEvents

Hi all

I have to write an application in VB.NET which monitors multiple files
at the time and notifies the user about changes. I thought to use
multiple instances of FileSystemWatcher in an array (the number of
instances i need is dynamic). Here is the code I wrote:

Dim arrFSW() As FileSystemWatcher
ReDim arrFSW(lstFiles.Items.Count - 1)
For i As Integer = 0 To lstFiles.Items.Count - 1
strFile = lstFiles.Items(i)
arrFSW(i) = New FileSystemWatcher
arrFSW(i).Path = "mypath"
arrFSW(i).Filter = "myfile"
arrFSW(i).NotifyFilter = (NotifyFilters.LastAccess Or
NotifyFilters.LastWrite Or NotifyFilters.FileName Or
NotifyFilters.DirectoryName)
AddHandler arrFSW(i).Changed, AddressOf FSWChanged
AddHandler arrFSW(i).Deleted, AddressOf FSWDeleted
AddHandler arrFSW(i).Renamed, AddressOf FSWRenamed
arrFSW(i).EnableRaisingEvents = True
Next

Private Shared Sub FSWChanged(ByVal source As Object, ByVal e As
FileSystemEventArgs)
Console.WriteLine("File: " & e.Name & " changed")
End Sub

Private Shared Sub FSWDeleted(ByVal source As Object, ByVal e As
FileSystemEventArgs)
Console.WriteLine("File: " & e.Name & " deleted")
End Sub

Private Shared Sub FSWRenamed(ByVal source As Object, ByVal e As
RenamedEventArgs)
Console.WriteLine("File: {0} renamed to {1}", e.OldName, e.Name)
End Sub

Now, the code does not raise any compilation error, but the
FileSystemWatcher does not raise the events since the array cannot be
declared as WithEvents. Does anybody have a solution for this issue?

Any help is greatly appreciated!

Greets

DiGa

Nov 21 '05 #1
2 4522
Hi everybody,

Sorry for anoying you. I found the problem which lays in wrong value
for the path variable. Problem solved.

Thank you!

Nov 21 '05 #2


DiGa wrote:
Hi everybody,

Sorry for anoying you. I found the problem which lays in wrong value
for the path variable. Problem solved.

Thank you!


Good cos that one had me stumped :) From the subject line I was
expecting to have to explain about AddHandler and so forth but you
clearly already knew that...

--
Larry Lard
Replies to group please

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rich Miller | last post by:
Previously posted on the VB newsgroup with no replies, so any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that...
13
by: David | last post by:
I have been working on trying to write a directory watcher service. One of the requirments is that it be able to watch multiple directories, not sub directories of one parent directory, but just...
1
by: PadovaBoy | last post by:
Hi! I try to develop a simple system for monitoring a sub directory of a web site and remake an xml file every time a sub-dir change it's name. I don't wont to use a window.service because, i want...
10
by: Kai Thorsrud | last post by:
Hi i'm an event Noob and i'm calling a class from my main module console app like this. I'm sorry if this is a lot of code to read but i can't see the error according to my book. Thanks a LOT. ...
0
by: Rich Miller | last post by:
Any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that instantiates a System.IO.FileSystemWatcher like so (the _watcher is...
1
by: Terry Olsen | last post by:
I have a console app that uses FileSystemWatcher to watch for a certain file to be created, then it reads the data out of the file, inserts it into an sql database, deletes the file and then...
1
by: GL | last post by:
I am trying to develop a prgram that randomly selects numbers for an addition program, then when the check answer button is pressed it colors the answer text field either green or red depending if...
1
by: Frederic H | last post by:
Hi, I have a problem when I try to open a new form with the Changed event (FileSystemWatcher) : the form hangs just after the paint. But I use the same function (OpenFormPerform) to open a new...
5
by: Philip Wagenaar | last post by:
I have a Windows Form application that monitors a directory using the System.IO.FileSystemWatcher. On the event created I run a sub that sends an xml file over http to a service. When I copy...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.