Archive for August, 2010

After creating a windows service, to move a file from one UNC path to another using a FileSystemWatcher, which, in turn,  monitors a UNC path of an FTP folder for a new file,  I received an unexpected error.

I wired up the FileSystemWatcher’s OnCreated event to monitor for the new file. However, when the event fires and the service tries to move the file to another UNC path an IOException exception is thown with a message “The process cannot access the file because it is being used by another process.”

After some investigation, I found that when the file is dropped into the directory, the event OnCreated event is fired, but, at that point, the file is still writing. As a workaround, I caught the exception and when the file is released, it fires the OnChanged event, where I can successfully move the file.

Not the prettiest solution, but it works!  Anyone with any better solutions, let me know.

If you ever find yourself in the situation where you’re unable to debug your application because you have inadvertently managed to disable configuration manager and put it into release mode at the same time. Here’s how to re-enable configuration manager.

Under Tools -> Options -> Projects and Solutions, you’ll see the Show Advanced Build Configurations option.

Show Advanced Build Configurations

Tick the show advanced build configurations box and your back in action.

I’m still puzzled how I managed to do this (maybe some crazy key stroke combination),  but its working again now.