OnChange object of FileSystemWatcher not recognized

  • Thread starter Thread starter pantagruel
  • Start date Start date
P

pantagruel

The following code:

FileSystemWatcher watcher = new FileSystemWatcher();
RenderingQ =
ConfigurationSettings.AppSettings["RenderingQ"];
watcher.Path = RenderingQ;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = "*.txt";

// Add event handlers.

watcher.Created += new FileSystemEventHandler(OnChanged);


// Begin watching.
watcher.EnableRaisingEvents = true;
raises the following error:

The name 'OnChanged' does not exist in the current context

So the question is what should I change it to?
 
pantagruel said:
The following code:

FileSystemWatcher watcher = new FileSystemWatcher();
RenderingQ =
ConfigurationSettings.AppSettings["RenderingQ"];
watcher.Path = RenderingQ;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = "*.txt";

// Add event handlers.

watcher.Created += new FileSystemEventHandler(OnChanged);


// Begin watching.
watcher.EnableRaisingEvents = true;
raises the following error:

The name 'OnChanged' does not exist in the current context

So the question is what should I change it to?

You make a method called OnChange so the event is pointing to it. You had
best find out the signature of that particular event, so that the correct
Event Args are passed to the function you need to make manually. Or you can
drop a FileSystemWatch on the form, go to Properties, the Event icon (the
Lightening bolt), Change and give it a name called OnChange to see what is
put there for the code.

You might want to do a GO TO on the InitializeComponent() to see what it put
there for the Control because your += new doesn't look right.
 
The following code:
FileSystemWatcher watcher = new FileSystemWatcher();
RenderingQ =
ConfigurationSettings.AppSettings["RenderingQ"];
watcher.Path = RenderingQ;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = "*.txt";
// Add event handlers.
watcher.Created += new FileSystemEventHandler(OnChanged);
// Begin watching.
watcher.EnableRaisingEvents = true;
raises the following error:
The name 'OnChanged' does not exist in the current context
So the question is what should I change it to?

You make a method called OnChange so the event is pointing to it. You had
best find out the signature of that particular event, so that the correct
Event Args are passed to the function you need to make manually. Or you can
drop a FileSystemWatch on the form, go to Properties, the Event icon (the
Lightening bolt), Change and give it a name called OnChange to see what is
put there for the code.

You might want to do a GO TO on the InitializeComponent() to see what it put
there for the Control because your += new doesn't look right.

hmm, found the error, I declared the OnChange method incorrectly.
Shouldn't code at midnight in bed.
 
Back
Top