470,602 Members | 1,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,602 developers. It's quick & easy.

File System Watcher

I am using the following code to monitor a directory for new files. The
problem is that when I add a new file to the directory the code creates two
events??? what do I have to do to limit it to only one event??

using System;

using System.IO;

namespace DirectoryWatcher


/// <summary>

/// Summary description for Class1.

/// </summary>

class DirectoryWatcher


/// <summary>

/// The main entry point for the application.

/// </summary>


public static void Main()


// Establish which directory to watch

FileSystemWatcher watcher = new FileSystemWatcher();

watcher.Path = @"C:\FTPIN";

// Setup things to be on the lookout for

watcher.NotifyFilter = NotifyFilters.FileName;

// Setup filter for specific file types

watcher.Filter = "*.*";

// Define event handlers

watcher.Created += new FileSystemEventHandler(OnChanged);

// Begin watching the directory

watcher.EnableRaisingEvents = true;

// Wait for user to quit program

Console.WriteLine(@"Press q to quit");



private static void OnChanged(object source, FileSystemEventArgs e)


Console.WriteLine("File: {0} {1}!", e.FullPath, e.ChangeType);



Nov 16 '05 #1
0 2429

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ron Vecchi | last post: by
7 posts views Thread by Allen Anderson | last post: by
2 posts views Thread by Jack David | last post: by
5 posts views Thread by ToddT | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.