Must have been a typo in my first post.
Here's all the code. But I still get the same error.
using System;
using System.IO;
namespace FileWatcherDaemon
{
/// <summary>
/// Summary description for fileWatcher.
/// </summary>
public class fileWatcher
{
public static void Main()
{
string[] args = System.Environment.GetCommandLineArgs();
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "C:\\Temp";
watcher.Filter = "*.txt";
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.EnableRaisingEvents = true;
watcher.Changed += new FileSystemEventHandler(OnChanged);
Console.WriteLine("Press \'q\' to Quit");
while(Console.Read()!='q');
}
private void OnChanged(object sender, FileSystemEventArgs e)
{
Console.WriteLine("File Changed");
Console.WriteLine("file: " + e.Name.ToString());
}
}
}
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP***********************@news.microsoft.com. ..
dm_dal <dm******@yahoo.com> wrote: I'm trying to compile the FileSystemWatcher example on MSDN but it won't
compile and gives the following build error:
1) An object reference is required for the nonstatic field, method,
or property 'FileWatcherDaemon.fileWatcher.OnChanged(object,
System.IO.FileSystemEventArgs)'
This is given on the following line:
watcher.Changed += new FileSystemEventHandler(Changed);
The above line doesn't exist in the sample - it's OnChanged, not
Changed.
I've just cut and paste the original from MSDN, and it compiles fine.
Which version of the MSDN are you using?
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too