Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. FileSystemWatcher question

FileSystemWatcher question

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
8 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alsvha
    wrote on last edited by
    #1

    Hiya all. I instantiated a filesystemwatcher and set it to monitor a directory filtered with a specific file. Then I made a method which handles the Changed event from the filesystemwatcher.... however when I save/alter the file the watcher monitors - I get the event called twice. Does anybody know why? Or possible what I need to look for?

    S 1 Reply Last reply
    0
    • A Alsvha

      Hiya all. I instantiated a filesystemwatcher and set it to monitor a directory filtered with a specific file. Then I made a method which handles the Changed event from the filesystemwatcher.... however when I save/alter the file the watcher monitors - I get the event called twice. Does anybody know why? Or possible what I need to look for?

      S Offline
      S Offline
      Stuart Wells
      wrote on last edited by
      #2

      When I first used this class I had this problem - but I don't have the problem anymore. To resolve my issue I no longer listen to CHange event, but to the Created, Renamed and Deleted events instead. Depends on what you need to know, but these covered my requirements.

      Stuart Wells Software Engineer

      H A 2 Replies Last reply
      0
      • S Stuart Wells

        When I first used this class I had this problem - but I don't have the problem anymore. To resolve my issue I no longer listen to CHange event, but to the Created, Renamed and Deleted events instead. Depends on what you need to know, but these covered my requirements.

        Stuart Wells Software Engineer

        H Offline
        H Offline
        Hendrik Debedts
        wrote on last edited by
        #3

        It's because a changed-event fires more than you probably expect, for example: - When you create a file - When you delete a file - When you rename a file - ...

        1 Reply Last reply
        0
        • S Stuart Wells

          When I first used this class I had this problem - but I don't have the problem anymore. To resolve my issue I no longer listen to CHange event, but to the Created, Renamed and Deleted events instead. Depends on what you need to know, but these covered my requirements.

          Stuart Wells Software Engineer

          A Offline
          A Offline
          Alsvha
          wrote on last edited by
          #4

          I have a file, in which I need to monitor changes, so I can't use any of the others. The file exits, so it isn't because it gets created that the watcher triggers twice. Both events are the "Changed" event.

          --------------------------- 127.0.0.1 - Sweet 127.0.0.1

          L D 2 Replies Last reply
          0
          • A Alsvha

            I have a file, in which I need to monitor changes, so I can't use any of the others. The file exits, so it isn't because it gets created that the watcher triggers twice. Both events are the "Changed" event.

            --------------------------- 127.0.0.1 - Sweet 127.0.0.1

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            I don't know for sure, but maybe you get one event for the content change, and one for the update of the LastWriteTime ?

            Luc Pattyn

            A 1 Reply Last reply
            0
            • A Alsvha

              I have a file, in which I need to monitor changes, so I can't use any of the others. The file exits, so it isn't because it gets created that the watcher triggers twice. Both events are the "Changed" event.

              --------------------------- 127.0.0.1 - Sweet 127.0.0.1

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              It depends on the file too. If it's a Word document, for example, you're not opening the orignal file. You actually open a copy of it. When you go to save the changes, the file is actually written to the temporary copy (Changed event), then the original file is deleted (Changed event) and the temporary file is renamed (Changed event) to the orignal filename.

              Dave Kreskowiak Microsoft MVP - Visual Basic

              A 1 Reply Last reply
              0
              • D Dave Kreskowiak

                It depends on the file too. If it's a Word document, for example, you're not opening the orignal file. You actually open a copy of it. When you go to save the changes, the file is actually written to the temporary copy (Changed event), then the original file is deleted (Changed event) and the temporary file is renamed (Changed event) to the orignal filename.

                Dave Kreskowiak Microsoft MVP - Visual Basic

                A Offline
                A Offline
                Alsvha
                wrote on last edited by
                #7

                it's an XML document, opened via notepad.

                1 Reply Last reply
                0
                • L Luc Pattyn

                  I don't know for sure, but maybe you get one event for the content change, and one for the update of the LastWriteTime ?

                  Luc Pattyn

                  A Offline
                  A Offline
                  Alsvha
                  wrote on last edited by
                  #8

                  Hmm - could be, could be.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups