about event and fileSystemWatcher class

P

PointMan

there is class A...

class A
{
FileSystemWatcher watcher;

public void Start()
{
fs= new FileSystemWatcher();
fs.Path = "C:\TEMP";
fs.NotifyFilter =
NotifyFilters.LastAccess | NotifyFilters.LastWrite |
NotifyFilters.FileName | NotifyFilters.DirectoryName;

fs.Filter = filter;

// Add event handlers.
fs.Created += new FileSystemEventHandler(OnChanged);


watcher.EnableRaisingEvents = true;


}

public void StopTicker()
{
fs.EnableRaisingEvents = false;
}

// public event Created FileWatcherChanged;

void OnChanged(object source, FileSystemEventArgs e)
{
// some code
}
}


and then i want to use this class on main class

especially, OnChanged want to use main class like this.

class main
{
a = new a();
a.Created += new FileSystemEventHandler(OnChanged);
a.Start();
}
void OnChanged(object source, FileSystemEventArgs e)
{
// some code
}


how can i have to do>?
 
J

Jon Skeet [C# MVP]

how can i have to do>?

It's not entirely clear *exactly* what you want to do. Do you want
a.Created to effectively proxy to the FileSystemWatcher? If so, just
use:

public event FileSystemEventHandler Created
{
add { watcher.Created += value; }
remove { watcher.Created -= value; }
}
 

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