OnChange object of FileSystemWatcher not recognized

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?
 
M

Mr. Arnold

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.
 
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?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top