FileSystemEventHandler的附加参数 [英] Additional parameters for FileSystemEventHandler

查看:200
本文介绍了FileSystemEventHandler的附加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序,该程序可以监视多个文件夹的文件创建并启动相同的操作,但每个文件夹的设置不同.我的问题是为FileSystemEventHandler指定一个额外的参数.我为每个目录创建一个新的FileWatcher来监视和添加Created-action的处理程序:

I'm trying to write a program that could monitor multiple folders for file creations and launch the same action but with different settings for each folder. My problem is in specifying an extra parameter for the FileSystemEventHandler. I create a new FileWatcher for each directory to monitor and add the handler for the Created-action:

foreach (String config in configs)
{
    ...
    FileWatcher.Created += new System.IO.FileSystemEventHandler(FileSystemWatcherCreated)
    ...
}

void FileSystemWatcherCreated(object sender, System.IO.FileSystemEventArgs e, MySettings mSettings)
{
    DoSomething(e.FullPath, mSettings);
}

如何获取传递给FileSystemWatcherCreated()的'mSettings'变量?

How could I get the 'mSettings' variable passed to FileSystemWatcherCreated()?

推荐答案

foreach (String config in configs)
{
    ...
    FileWatcher.Created += (s,e) => DoSomething(e.FullPath, mSettings);
    ...
}

这篇关于FileSystemEventHandler的附加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆