You can't put a method within a method like that, or event handler within an event handler, such as it is; you will need to define the FileSystemWatcher handler alongside the timer handler. But your watcher will do the ticking-over style monitoring for you, and raise the event when that occurs according to it, and not your timer.
To explain a little, it would make sense to put it like this, and you don't have that particular error (or set of errors) any more:
private void timer1_tick (object sender, EventArgs xz) {
}
void SysWatch_Created(object Sender, FileSystemEventArgs w) {
MessageBox.Show("File " + w.FullPath + "Creato");
}
However, then you still need to call it at the interval, and calling the handler method manually doesn't make much sense here. Consider the following:
private void timer1_tick (object sender, EventArgs xz) {
SysWatch_Created(this, null);
}
The sender might be expected to be a FileSystemWatcher, but not necessarily so that's of the least concern: otherwise, what do you expect to pass for where I place null
in this instance? Only the watcher has this information in this context.
Back to the point. You don't need a timer, FileSystemWatcher will do the polling internally and inform you, because you tell it to (Created += new FileSystemEventHandler(SysWatch_Created);
). You can't specifically set the polling interval of this thing, though.