FileSystemWatcher doesn’t work on Vista

.NET, Vista No Comments »

The FileSystemWatcher class is part of the .NET framework and is used to watch for changes in directories or files.  For programs that need to monitor particular files, this class is perfect and very helpful.  I wrote a program to parse a log file and used the FileSystemWatcher class to monitor the log file  and raise an event when a new line is added to the log.  My code worked great on Windows XP but after upgrading to Windows Vista I noticed that the FileSystemWatcher stopped working.

The FileSystemWatcher seems to have a bug on Vista where  if the file is currently open by another program (as in the case with real-time log files) then it will not notice any changes made to the file.  From my own experience I found that if I used Windows Explorer to browse to the log folder (or refreshed the folder if Windows Explorer was already there) then the FileSystemWatcher would finally pick up the changes.  I experienced this bug on .NET 2.0 so I’m not certain if it exists in .NET 1.1 or 3.0 on Vista.

I eventually came up with a workaround for my particular program.  You basically need to add  your own timer which will check the file for modifications.  You could create your own code to act as a FileSystemWatcher and look for new lines added.  But this involves rewriting your code.  Another solution is to use a FileInfo object to help the FileSystemWatcher.  In my program I created a timer that would fire once per second.  The timer creates a FileInfo object for the same log file that the FileSystemWatcher is currently watching.  It will then call the Refresh method of the FileInfo object.  Calling the Refresh method will cause the FileSystemWatcher to notice any changes to the file and raise the proper event like it is supposed to.  Since the timer code is so short there is no noticeable performance increase.  This is the preferred workaround since you don’t need to modify any of your existing code.  Additionally, whenever this bug is fixed you can just remove the timer and you will not have to rewrite any code.  If your program also runs on other operating systems (like XP or 2003 server) then you could probably add some additional code to check which operating system is running and only use the timer code if it is running on Vista.

I discussed this particular bug with others on the MSDN forums at: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1569013&SiteID=1

Enable Vista’s Aero interface and get the full Vista experience

Vista No Comments »

A few months ago I upgraded from Windows XP to Vista (64-bit).  I must say I’m impressed with Vista so far and enjoy using it.  One of the things I had been hearing about was the new Aero interface.  After installing Vista I thought, “this new interface is ok, but it’s nothing special, why was everyone talking about it?”  I didn’t think much about it, but one day I discovered something called the “Windows Experience Index”.

You can find this rating in the Control Panel under System or alternatively under “Performance Information and Tools”.  Basically, Vista can check various parts of your system and assign a rating to each part (on a scale of 1 – 5.9).  The parts are: Processor, Memory (RAM), Graphics, Gaming graphics, and Primary hard disk.  After examining your system, Vista will determine a “base score” which you can supposedly use as a reference for purchasing software in the future (e.g. Will it run on my system?).

That sounds like an interesting little tool but not very important.  However, I discovered the importance of the Windows Experience Index after installing Vista.  I’m not sure if this is a common problem or it was just a fluke, but when I did a fresh install of Vista the Windows Experience Index was set to 1.0 and it was never updated.  Since this value was set so low, Vista turned off almost the entire Aero interface by default.  After I found this value in the Control Panel and updated it, my computer received a base score of 4.0 (5.4 on the Aero rating).  Immediately after the test finished, Vista automatically enabled all of the Aero interface features and my Vista experience immediately changed.

Now I could see what all the talk about Aero was about – I was completely missing out before!  I now had transparent windows, new effects when minimizing or maximizing windows, enhanced previews of programs in the taskbar or when alt tabbing, the new window switcher, and a whole lot more.

As a first time Vista user I didn’t realize what I was missing.  I also didn’t realize I had to manually update the Windows Experience Index or manually enable the Aero features in the Control Panel.  It seems like Vista should have automatically prompted me to update the Windows Experience Index shortly after completing the installation.  My system’s graphics capabilities are more than enough for Aero, but it had turned off all the features by default.

So if your index rating is still at 1.0 you should definitely have Vista update that value and then you can be sure you are getting the full experience with Aero.

© Phillip Hansen | Original theme by N.Design Studio
Entries RSS Comments RSS Log in