Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create FileSystemWatcher at runtime?

Status
Not open for further replies.

beefeater267

Programmer
Apr 6, 2005
79
Hi, I need to create a filesystemwatcher at runtime based on entries in XML document. However, it does not seem to work. (The event NEVER fires). Can anyone help me out w/ what is wrong w/ this code?


I have a function that does the following code:

//loop through our Watcher Nodes
private void CreateFSWs()
{
for (int k=0; k<fileWatcherNodes.Count; k++)
{
fileWatcherNode = fileWatcherNodes[k];
lookDirectory = @"C:";
fsw = new FileSystemWatcher(lookDirectory);
((System.ComponentModel.ISupportInitialize)(fsw)).BeginInit();
fsw.EnableRaisingEvents = true;
fsw.SynchronizingObject = this;
fsw.Changed+=new FileSystemEventHandler(fsw_Changed);
fsw.SynchronizingObject = this;
}
}

private void fsw_Changed(object sender, FileSystemEventArgs e)
{
string x = "";
}

Anybody know what is wrong w/ this? Can anyone maybe provide a sample of a FSW created a runtime that has this Changed event that fires?

Thanks a million
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top