C#编写的Window Service多线程出项的致命问题,望高手解答

lwchq 2009-12-25 04:25:47
I wrote a C# window service to minotor a particular folder, once there're subfolder, something will be dome to the subfolder. codes like,

FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = MonitoringFolderPath;
watcher.NotifyFilter = NotifyFilters.DirectoryName;
watcher.IncludeSubdirectories = true;
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;


the problems is that when there're several/many folders arriving, the service program itself sometime would be gone in runtime. I guess it may due to AntiVirus or SMP(multi-processor)/hyperthreading.

Does anyone meet such problem?
Any comment is welcomed.

Thanks.
...全文
139 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwchq 2009-12-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 kingdomgps 的回复:]
引用 1 楼 wjq 的回复:
I wrote a C#Windows service tomonitora particular folder, once there're subfolders, something will bedoneto the subfolder.
…………
…………

何必用英文呐………………


其实老外不会像你这样在乎这些小错误的,能看懂就成
又不是写合同呵呵

据说微软的FileSystemWatcher有BUG,会导致事件被多次触发
可以借鉴log4net的处理方式,事件触发后不立即执行,
而是启动一个timmer,用timmer来等待500ms,再在timmer的事件里来执行处理程序
[/Quote]

非常感谢你的答复
hejialin666 2009-12-25
  • 打赏
  • 举报
回复
文件监视:

FileSystemWatcher m_FileWatcher = new FileSystemWatcher();



//文件监视事件,括号里为方法名(触发的事件),在这个方法中写具体的操作

FileSystemEventHandler m_fileSystemEvent = new FileSystemEventHandle(fileSystemWatcher1_Created);



string m_path =“”; //监视的文件夹的路径



m_FileWatcher.BeginInit();

m_FileWatcher.Path = m_path;

m_FileWatcher.Created += m_fileSystemEvent; // .Changed/.Deleted/.Disposed/.Renamed

m_FileWatcher.EnableRaisingEvents = true; //文件监视事件可以运行

m_FileWatcher.EndInit();



private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)

{

m_FileWatcher.WaitForChanged(System.IO.WatcherChangeTypes.Changed, 500);

}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hejialin666/archive/2008/07/24/2705604.aspx
注册失败 2009-12-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wjq 的回复:]
I wrote a C#Windows service tomonitora particular folder, once there're subfolders, something will bedoneto the subfolder.
…………
…………

何必用英文呐………………
[/Quote]

其实老外不会像你这样在乎这些小错误的,能看懂就成
又不是写合同呵呵

据说微软的FileSystemWatcher有BUG,会导致事件被多次触发
可以借鉴log4net的处理方式,事件触发后不立即执行,
而是启动一个timmer,用timmer来等待500ms,再在timmer的事件里来执行处理程序
cj548820 2009-12-25
  • 打赏
  • 举报
回复
English...i don't mingbai!
tzs2304 2009-12-25
  • 打赏
  • 举报
回复
up
wjq 2009-12-25
  • 打赏
  • 举报
回复
I wrote a C# Windows service to monitor a particular folder, once there're subfolders, something will be done to the subfolder.
…………
…………

何必用英文呐………………

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧