about event and fileSystemWatcher class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PointMan

    #1

    about event and fileSystemWatcher class

    there is class A...

    class A
    {
    FileSystemWatch er watcher;

    public void Start()
    {
    fs= new FileSystemWatch er();
    fs.Path = "C:\TEMP";
    fs.NotifyFilter =
    NotifyFilters.L astAccess | NotifyFilters.L astWrite |
    NotifyFilters.F ileName | NotifyFilters.D irectoryName;

    fs.Filter = filter;

    // Add event handlers.
    fs.Created += new FileSystemEvent Handler(OnChang ed);


    watcher.EnableR aisingEvents = true;


    }

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

    // public event Created FileWatcherChan ged;

    void OnChanged(objec t source, FileSystemEvent Args 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 FileSystemEvent Handler(OnChang ed);
    a.Start();
    }
    void OnChanged(objec t source, FileSystemEvent Args e)
    {
    // some code
    }


    how can i have to do>?




  • Jon Skeet [C# MVP]

    #2
    Re: about event and fileSystemWatch er class

    PointMan <somequestion@g mail.comwrote:

    <snip>
    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 FileSystemWatch er? If so, just
    use:

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

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    Working...