FileSystemWatcher WinXP versus Win2003

M

Meya-awe

Hi,
I have a C# program which creates a FileSystemWatcher and sets
IncludeSubdirectories property to true with filter set to "*.txt". The
program runs fine under WinXP but in Win2003, it does not always work.
specifically another program is writing into the directory being
monitored by my app. When i do a copy from command prompt into the
directory, my app picks it up. But when the other app writes a file into
the directory being monitored, my app does not. All the testing i have
done with my app on XP involved the copying of the file or opening it
using notepad and saving it back. The NotifyFilter is set to LastWrite.
But i am capturing the Created and Changed events using:
_fsWatcher.Created += new FileSystemEventHandler(someFunc)
_fsWatcher.Changed += new FileSystemEventHandler(someFunc)
where the someFunc is defined as a private void.
The copy does not work on the Win2003 but when i use notepad to save the
file on win2003, my app sees the event. I want my program to capture the
first time creation of the file on the directory and not when i use
notepad to save it.
Any ideas why the difference?
thanks,
BRAMOIN
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Maybe your program is getting error when try to access the file ( it may be
still in used by the originator ). What if you put a try/catch with a
message or write to a log if you find a problem.
Also with that set of events you may get duplicated events being fired for
the same file, be aware of that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top