[英]FileWatcher in Windows Service suddenly stops working
I'm running a windows service in Windows 2003. I've been adding/changing code to it every day for the last month, and everyday for the last month my filewatcher has been working. 我正在Windows 2003中运行Windows服务。在上个月,每天都在向其中添加/更改代码,在上个月,我的FileWatcher一直在工作。 However, it stopped working today for some odd reason.
但是,由于某种奇怪的原因,它今天停止了工作。 If I revert back to old code, it still won't raise events.
如果我恢复为旧代码,它仍然不会引发事件。 I've tested the same code on my Win7 machine and it is working fine.
我已经在Win7机器上测试了相同的代码,并且工作正常。 I'm assuming there is an external process interfering but I'm not even sure what to look for.
我假设有一个外部过程在干扰,但是我什至不确定要寻找什么。
Here is the relevant code: 以下是相关代码:
private void InitializeComponent()
{
this.processfileWatcher = new System.IO.FileSystemWatcher();
((System.ComponentModel.ISupportInitialize) (this.processfileWatcher)).BeginInit();
this.processfileWatcher.EnableRaisingEvents = true;
this.processfileWatcher.Filter = "done.txt";
this.processfileWatcher.Changed += new System.IO.FileSystemEventHandler(this.processfileWatcher_Changed);
this.ServiceName = "Service1";
((System.ComponentModel.ISupportInitialize)(this.processfileWatcher)).EndInit();
}
private void processfileWatcher_Changed(object sender, System.IO.FileSystemEventArgs e)
{
try
{
processfileWatcher.EnableRaisingEvents = false;
//Do stuff here
Debug.WriteLine(" End of processfileWatcher for: " + e.FullPath);
}
finally
{
processfileWatcher.EnableRaisingEvents = true;
}
}
Through debug statements I can confirm that I am reaching the end of my onStart() method. 通过调试语句,我可以确认我已经到达onStart()方法的末尾。
If something is causing a lot of rapid disk changes you may be running out of buffer before you have the chance to catch the thing you are looking for, or your service's credentials may not be working for what you are monitoring. 如果某种原因导致大量磁盘快速更改,则在您有机会捕获所需内容之前,您可能已经用尽缓冲区,或者您的服务凭据可能不适用于您正在监视的内容。
Try granting explicit permissions then look for the buffer issue by adding a handler for the fileystemwatcher's error event. 尝试授予显式权限,然后通过为fileystemwatcher的error事件添加处理程序来查找缓冲区问题。
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.error%28v=vs.100%29.aspx http://msdn.microsoft.com/zh-cn/library/system.io.filesystemwatcher.error%28v=vs.100%29.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.