Nancy Street

FileSystemWatcher Traps

Click to see the Site Map
HomeInfoMusicGalleryPetsGeoHobbiesGeo
Site MapWhat's NewRecent ChangesContactsServer StatisticsSite Information Home « Computers « DevBlog

Back to: Development Blog Contents

The .NET SystemFileWatcher class is a fabulous wrapper over Win32 file system functionality, but there are some tricks and traps in using it reliably.

Initial Group Post

-----Original Message-----
From: Greg Keogh [mailto:greg@mira.net]
Sent: Wednesday, 17 March 2004 23:01
To: 'dotnet@stanski.com'
Subject: FileSystemWatcher case and short names

Has anyone here worked deeply with the FileSystemWatcher class?

I’ve been using the class intensely for the last few days, and I’ve found some weird and unexpected behaviour.

My app shows lists of files in a grid, and when the watcher is notified of changes it pushes then into a queue which a background thread lazily polls to update the UI grid.

I thought I had a dreadful bug in my app, as randomly the grid would not update. I eventually found that the watcher occasionally (randomly it seems to me) returns the name of the changed file in short 8.3 format with a tilde. I can’t find a pattern to it yet.

I also found that the file name is returned in lower case on a rename event.

The short name problem wasted a lot of my time. I later found these meagre references:

http://www.dotnet247.com/247reference/msgs/20/101956.aspx
http://discuss.develop.com/archives/wa.exe?A2=ind0305c&L=dotnet-clr&T=0&F=&S=&P=19573

A Reply

-----Original Message-----
From: dotnet-owner@stanski.com [mailto:dotnet-owner@stanski.com] On Behalf Of Bill
Sent: Thursday, 18 March 2004 08:39
To: dotnet@stanski.com
Subject: RE: [aus-dotnet] FileSystemWatcher case and short names

Greg,

This might help; it is from William Bartholomew’s Blog:

http://william.bartholomew.com.au/DotBlog/archive/2004/03/17/236.aspx | Comments
A must for anyone who has suffered some of FileSystemWatcher's quirks:
http://weblogs.asp.net/ashben/archive/2003/10/14/31773.aspx

Bill

My Final Comment

-----Original Message-----
From: Greg Keogh
Sent: Wednesday, 24 March 2004 09:42
To: dotnet@stanski.com
Subject: RE: [aus-dotnet] FileSystemWatcher case and short names

A final note on this issue:

One of the links almost pointed to KB article Q290601 which explains exactly why I was getting short file names from the watcher. I never found this article in the Win32 area last week because I was searching for the wrong keywords and the link to it was broken. I had to do exactly as the article suggests:

An application would need to keep a cache of both short
and long file names to match them up when the
notification is received.


Luckily it resulted in only an extra 40 lines of code, most of it being interop calls to GetShortPathName.

Greg

Back to: Development Blog Contents


Contact Information | PGP Keys | Site Map | What's New | Visitor Book
Last Updated: 06-Aug-2007 21:09
Copyright © 1999-2007 Orthogonal Programming