FileSystemWatcher Changed Event Double Activation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tomb

    FileSystemWatcher Changed Event Double Activation

    I'm using VB.net 2003 and a FileSystemWatch er. The Changed event gets
    called twice for every change in the folder I'm watching. To build the
    functionality, I'm manually changing a text file. As soon as I save the
    changed file, the event is called, which is great. But then the event
    is called again almost immediately. That causes some serious issues for
    my program.

    Has anyone seen this before? Is there a way to stop it?

    Thanks

    Tom
  • Lance Wynn

    #2
    Re: FileSystemWatch er Changed Event Double Activation

    I had a problem with this when my notifyfilter contained 2 filters that
    could both conveivably be hit with a single change ie:

    fsw.NotifyFilte r = NotifyFilters.L astWrite Or NotifyFilters.S ize

    If I write to the file, and the filesize also changes, then this gets raised
    once for the lastwrite, and once for the size change. (In the case of
    notepad, it seems the Size change happens regardless as I think notepad
    re-writes the complete file.

    In my case, I just used the lastwrite notification filter, and that solved
    my problem, because all I cared about was whether the file had been written
    to.



    Lance





    "tomb" <tomb@technetce nter.comwrote in message
    news:2zFqj.6846 0$Mu4.47698@big news7.bellsouth .net...
    I'm using VB.net 2003 and a FileSystemWatch er. The Changed event gets
    called twice for every change in the folder I'm watching. To build the
    functionality, I'm manually changing a text file. As soon as I save the
    changed file, the event is called, which is great. But then the event is
    called again almost immediately. That causes some serious issues for my
    program.
    >
    Has anyone seen this before? Is there a way to stop it?
    >
    Thanks
    >
    Tom

    Comment

    • tomb

      #3
      Re: FileSystemWatch er Changed Event Double Activation

      This sounded like it should resolve the issue, but it didn't. I set the
      filter to lastwrite, and the changed event still gets called twice. Is
      this a bug in V2003?

      T

      Lance Wynn wrote:
      I had a problem with this when my notifyfilter contained 2 filters that
      could both conveivably be hit with a single change ie:
      >
      fsw.NotifyFilte r = NotifyFilters.L astWrite Or NotifyFilters.S ize
      >
      If I write to the file, and the filesize also changes, then this gets raised
      once for the lastwrite, and once for the size change. (In the case of
      notepad, it seems the Size change happens regardless as I think notepad
      re-writes the complete file.
      >
      In my case, I just used the lastwrite notification filter, and that solved
      my problem, because all I cared about was whether the file had been written
      to.
      >
      >
      >
      Lance
      >
      >
      >
      >
      >
      "tomb" <tomb@technetce nter.comwrote in message
      news:2zFqj.6846 0$Mu4.47698@big news7.bellsouth .net...
      >I'm using VB.net 2003 and a FileSystemWatch er. The Changed event gets
      >called twice for every change in the folder I'm watching. To build the
      >functionalit y, I'm manually changing a text file. As soon as I save the
      >changed file, the event is called, which is great. But then the event is
      >called again almost immediately. That causes some serious issues for my
      >program.
      >>
      >Has anyone seen this before? Is there a way to stop it?
      >>
      >Thanks
      >>
      >Tom
      >
      >

      Comment

      • Lance Wynn

        #4
        Re: FileSystemWatch er Changed Event Double Activation

        It must be the way you are testing the file. If you are using notepad, I
        think it resets the file, and rewrites the whole thing.
        In my case, I had a lazy reader that read the tail end of a log file when it
        changed. As I recall I saw this problem when using notepad to add lines to
        the end of the file. I just tested with both filters in place, and used:
        echo test >test.txt
        from a command line to append text to the end of the file, and it works as
        expected even with both filters in place. So I suspect my original post was
        incorrect as to the cause. And the actual culprit is the way notepad
        modifies the file.


        "tomb" <tomb@technetce nter.comwrote in message
        news:2XHqj.6852 5$Mu4.63364@big news7.bellsouth .net...
        This sounded like it should resolve the issue, but it didn't. I set the
        filter to lastwrite, and the changed event still gets called twice. Is
        this a bug in V2003?
        >
        T
        >
        Lance Wynn wrote:
        >I had a problem with this when my notifyfilter contained 2 filters that
        >could both conveivably be hit with a single change ie:
        >>
        >fsw.NotifyFilt er = NotifyFilters.L astWrite Or NotifyFilters.S ize
        >>
        >If I write to the file, and the filesize also changes, then this gets
        >raised once for the lastwrite, and once for the size change. (In the
        >case of notepad, it seems the Size change happens regardless as I think
        >notepad re-writes the complete file.
        >>
        >In my case, I just used the lastwrite notification filter, and that
        >solved my problem, because all I cared about was whether the file had
        >been written to.
        >>
        >>
        >>
        >Lance
        >>
        >>
        >>
        >>
        >>
        >"tomb" <tomb@technetce nter.comwrote in message
        >news:2zFqj.684 60$Mu4.47698@bi gnews7.bellsout h.net...
        >>I'm using VB.net 2003 and a FileSystemWatch er. The Changed event gets
        >>called twice for every change in the folder I'm watching. To build the
        >>functionality , I'm manually changing a text file. As soon as I save the
        >>changed file, the event is called, which is great. But then the event
        >>is called again almost immediately. That causes some serious issues for
        >>my program.
        >>>
        >>Has anyone seen this before? Is there a way to stop it?
        >>>
        >>Thanks
        >>>
        >>Tom
        >>

        Comment

        • tomb

          #5
          Re: FileSystemWatch er Changed Event Double Activation

          Well, I tested it using the program that would actually be affecting the
          files. It is a vb.net application using a dataset. The dataset just
          calls WriteXml() to save the data it is holding.

          My FileSystemWatch er captures the file update, but it is still being
          activated twice. This is not good.

          Can you think of some way around this? I was thinking of using a flag,
          but I can't figure out how to make that work. The file could
          conceivably be updated every 60 seconds. I could deactivate the watcher
          for 20 seconds immediately upon activation, but that seems so cloogy.

          Thanks,

          T


          Lance Wynn wrote:
          It must be the way you are testing the file. If you are using notepad, I
          think it resets the file, and rewrites the whole thing.
          In my case, I had a lazy reader that read the tail end of a log file when it
          changed. As I recall I saw this problem when using notepad to add lines to
          the end of the file. I just tested with both filters in place, and used:
          echo test >test.txt
          from a command line to append text to the end of the file, and it works as
          expected even with both filters in place. So I suspect my original post was
          incorrect as to the cause. And the actual culprit is the way notepad
          modifies the file.
          >
          >
          "tomb" <tomb@technetce nter.comwrote in message
          news:2XHqj.6852 5$Mu4.63364@big news7.bellsouth .net...
          >This sounded like it should resolve the issue, but it didn't. I set the
          >filter to lastwrite, and the changed event still gets called twice. Is
          >this a bug in V2003?
          >>
          >T
          >>
          >Lance Wynn wrote:
          >>I had a problem with this when my notifyfilter contained 2 filters that
          >>could both conveivably be hit with a single change ie:
          >>>
          >>fsw.NotifyFil ter = NotifyFilters.L astWrite Or NotifyFilters.S ize
          >>>
          >>If I write to the file, and the filesize also changes, then this gets
          >>raised once for the lastwrite, and once for the size change. (In the
          >>case of notepad, it seems the Size change happens regardless as I think
          >>notepad re-writes the complete file.
          >>>
          >>In my case, I just used the lastwrite notification filter, and that
          >>solved my problem, because all I cared about was whether the file had
          >>been written to.
          >>>
          >>>
          >>>
          >>Lance
          >>>
          >>>
          >>>
          >>>
          >>>
          >>"tomb" <tomb@technetce nter.comwrote in message
          >>news:2zFqj.68 460$Mu4.47698@b ignews7.bellsou th.net...
          >>>I'm using VB.net 2003 and a FileSystemWatch er. The Changed event gets
          >>>called twice for every change in the folder I'm watching. To build the
          >>>functionalit y, I'm manually changing a text file. As soon as I save the
          >>>changed file, the event is called, which is great. But then the event
          >>>is called again almost immediately. That causes some serious issues for
          >>>my program.
          >>>>
          >>>Has anyone seen this before? Is there a way to stop it?
          >>>>
          >>>Thanks
          >>>>
          >>>Tom
          >

          Comment

          Working...