473,414 Members | 1,775 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,414 software developers and data experts.

fileSystemWatcher problem

My program has two instances of a control have fileSystemWatchers that
are set to monitor the same directory for changes. When they are
watching a directory on the local machine, it works fine, two events
are received. However, when I am watching a directory on a machine
over the network by setting the fileSystemWatchers' path to i.e.
//anotherMachine/c/aDir then only one instance of the
fileSystemWatcher receives a FileSystemEvent. I have dug around and
have seen that others have had this problem. The only suggestions was
to have a single watcher that passes on the event to the two objects
that require it, a hack. Both the remote machine and the local machine
are running XP pro.

I am sorry if this is a double post, I just never saw my first post show up.

I wrote a sample console app that displays the same problem.

using System;
using System.IO;
using System.Collections;

namespace fileWatcherProgram
{
public class WatcherInstance
{
FileSystemWatcher watcher;
public WatcherInstance(string path)
{
watcher = new FileSystemWatcher();
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.Path= path;
watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName;
watcher.Filter = ""; // watch all files
watcher.IncludeSubdirectories = true; // look at all subdirectories
watcher.EnableRaisingEvents = true; // fire off the watcher
}

private void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine("File: {0} {1}", e.FullPath, e.ChangeType.ToString("G"));
}

private void OnRenamed(Object source, RenamedEventArgs e)
{
Console.WriteLine("File: {0} Renamed to {1}", e.OldFullPath,
e.FullPath);
}
}
public class Watcher
{
[STAThread]
public static void Main(String[] args)
{
if(args.Length < 1)
{
Console.WriteLine("Usage: Watcher.exe <directory>");
}
else
{
ArrayList FileSystemWatchers = new ArrayList();
for(int i=0; i<2; i++)
{

WatcherInstance watcher = new WatcherInstance(args[0]);
FileSystemWatchers.Add(watcher);
}
}

Console.WriteLine("Press Enter to quit the sample\r\n");
Console.ReadLine();
}
}
}
Nov 16 '05 #1
0 1261

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

Similar topics

4
by: Josh Usovsky | last post by:
I'm setting up a watched folder using FileSystemWatcher. When I drop a small file into the watched folder, I can respond to a .Created event and process the file with other code. However, if I try...
0
by: cxw0106 | last post by:
Hello, I have some weird problem with the FileSystemWatcher. I have developed an application that monitors a network directory for file changes of a certain file type. The program runs well for...
2
by: Paul | last post by:
Hi, I've been developing an application in VB.NET that uses the FileSystemWatcher and a popup notification in order to tell me when files have been downloaded. The FileSystemWatcher code in...
7
by: Allen Anderson | last post by:
I'm trying to figure out a way to catch when a file has been written to a directory. I currently have it where I can catch when the file begins writing, but this isn't helpful as I need to know...
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...
3
by: Stampede | last post by:
Hi, I write an application which waits for incomming files in a specified directory. I thought, that using the FileSystemWatcher would be the best, as it does exactly what I need. But now I have...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
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...
2
by: kmcnet | last post by:
Hello Everyone and thanks for your help in advance. I have been battling a problem for nearly a month with the FileSystemWatcher component. Basically, what I am trying to do it to monitor three...
5
by: =?Utf-8?B?Sm9obiBT?= | last post by:
I am trying to find out if there is a way to tell if there is already a filesystemwatcher (created by a webservice) monitoring a folder. I have a webservice that creates a filesystemwatcher,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.