日期:2014-05-17  浏览次数:20888 次

FileSystemWatcher 怎么传参数到委托中?

foreach (KeyValuePair<int, Pictures> list in pictureList)//遍历字典生成图片
            {
                if (GenTecPic(list.Value.datapath, list.Value.macropath, 0))
                {
                    FileSystemWatcher watcher = new FileSystemWatcher();//设置监视器
                    watcher.Path = list.Value.datapath;
                    watcher.Changed += new FileSystemEventHandler(TecDat_Changed);
                    watcher.Created += new FileSystemEventHandler(TecDat_Changed);
                    watcher.EnableRaisingEvents = true;
                    list.Value.watcher = watcher;
                }
            }
            timer_tecplot.Enabled = true;

委托:

void TecDat_Changed(object sender, FileSystemEventArgs e)
        {
            
        }

字典里有几个我就会建几个监视器,在TecDat_Changed中我需要得到别的参数来生成我的图片。
现在有2种想法,不知道哪个可以实现?
1.我想知道是哪个watcher,这样就可以在字典中根据watcher来找到其他数据了;
2.在上面中我想把list.Value.macropath作为参数能传给委托。

急啊!!

------解决方案--------------------
最原始的(在.net1.1就支持的)是可以创建一个调用类型,例如
public class MytecProxy
{
   public string path;
   ......以及其它任何必要的参数

   public void TecDat_Changed(object sender, FileSystemEventArgs e)
   {
        //在这里,你就可以访问到所有参数             
   }
}

然后调用时写
MyTecPr