FileSystemWatcher的一段时间后停止筹款活动 [英] FileSystemWatcher stops raising events after a period of time
本文介绍了FileSystemWatcher的一段时间后停止筹款活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们已经建立了一个侦听文件夹与 FileSystemWatcher的
,当我们创建处理文件等窗口服务。但几天之后,事件停止工作。
We have built a window service that listens to folders with FileSystemWatcher
, when created we process the file and so on. But after couple of days the event stops working.
- 是否有可能,它被垃圾收集器(GC)收集的?
- 是否GC收集它持有类(这是一个单)?
- 我应该使用弱事件?
- 请我有指事件中的错误被注销?
- Is it possible that it being collected by the garbage collector (GC)?
- Does the GC collect it holding class (which is a singleton)?
- Should I use a weak event?
- Do I have a bug that means the event gets unregistered?
我怎么想的问题是,FSW有一个内部缓冲区,当它溢出的错误,采取这种一看的文章的报价代码来解决这个问题。结果
希望这有助于任何人。
What i think the problem is, that FSW has an internal buffer, when it overflows its an error, take a look in this article that offer code to solve this problem.
Hope this help anyone.
推荐答案
一个几件事情来尝试,因为建议的这里:
A couple of things to try, as suggested here:
- 在计时器滴答事件处理程序,做你的Tick事件处理之前,停止计时,并重新启动它退出处理程序
- 之前包装在try / catch块的计时器代码,看看发生了什么
- 阅读的的System.Timers.Timer类的已用事件不会在Windows服务错误描述/修复,看看有没有可以帮助你提高
- In the timer tick event handler, stop your timer before doing your tick event handling, and restart it before exiting the handler
- Wrap your timer code in a try/catch block to see what's happening.
- Read the Elapsed event of the System.Timers.Timer class is not raised in a Windows service bug description/fix and see if that helps you.
在总结:
protected virtual void TimerTick(object sender, EventArgs e)
{
// stop your timer
this.timer.Stop();
try
{
// TODO: add event handler specifics
}
catch
{
// TODO: add some logging to help you see what's going on
}
// restart your timer
this.timer.Start();
}
这篇关于FileSystemWatcher的一段时间后停止筹款活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文