FileSystemWatcher 删除事件处理程序
由于某种原因,我无法从 FileSystemWatcher 中删除事件处理程序。
这就是我所拥有的,
void Start()
{
ivFileSystemWatcher = new FileSystemWatcher();
ivFileSystemWatcher.Changed +=
new FileSystemEventHandler(ivFileSystemWatcher_Changed);
}
void Stop()
{
ivFileSystemWatcher.Changed -=
new FileSystemEventHandler(ivFileSystemWatcher_Changed);
ivFileSystemWatcher.Dispose();
}
当我调用开始时,我开始接收更改事件,但是当我调用停止时,我期望事件停止,但它们仍在引发。
For some reason I can not remove an event handler from the FileSystemWatcher.
This is what I have
void Start()
{
ivFileSystemWatcher = new FileSystemWatcher();
ivFileSystemWatcher.Changed +=
new FileSystemEventHandler(ivFileSystemWatcher_Changed);
}
void Stop()
{
ivFileSystemWatcher.Changed -=
new FileSystemEventHandler(ivFileSystemWatcher_Changed);
ivFileSystemWatcher.Dispose();
}
When I call start I start receiving the change events, but when I call stop I am expecting the events to stop but they are still being raised.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过将
EnableRaisingEvents
设置为false
:在没有看到代码的其余部分的情况下,我不相信这是
Dispose()
的最佳位置>...Have you tried setting
EnableRaisingEvents
tofalse
:Without seeing the rest of your code, I'm not convinced that's the best place for the
Dispose()
...