3

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.

  • 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?

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.

Dori
  • 915
  • 1
  • 12
  • 20
guyl
  • 2,158
  • 4
  • 32
  • 58
  • 4
    These are very vague questions, and are difficult to answer without more context. The garbage collector won't collect anything that still has a reference to it (in an object that itself isn't collectible, etc), so as long as you are keeping a reference to your singleton, you should be okay. – Mike Caron Jul 12 '11 at 22:23

1 Answers1

-1

A couple of things to try, as suggested here:

In summary:

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();
}
Community
  • 1
  • 1
Gustavo Mori
  • 8,319
  • 3
  • 38
  • 52
  • This is exactly what i have done in our `Timer` classes, yet in our `FileSystemWatcher` the events stop responding after some time – guyl Jul 13 '11 at 06:17
  • 1
    Looks like you are using the 3rd suggestion as the answer to your ealier post here: http://stackoverflow.com/questions/6166339/timers-under-window-service-stop-working-after-couple-of-days – Gustavo Mori Jul 13 '11 at 06:49
  • 2
    How is this answer even related to the question? The question is about `FileSystemWatcher`, the answer is about `Timer`. – Rotem Aug 18 '13 at 08:14