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. C#
  4. FileSystemWatcher vs. Own file system polling

FileSystemWatcher vs. Own file system polling

Scheduled Pinned Locked Moved C#
javascriptvisual-studiosysadminhelpquestion
5 Posts 3 Posters 0 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.
  • C Offline
    C Offline
    C Scharbe
    wrote on last edited by
    #1

    Can any body tell me the advantages and disadvantages of both kinds to get to know if a file is in a specified directory. I have a directory in the network and a application that should work with the file took into the directory. I try to do it with a FileSystemWatcher, but the problem is, if the network connection failed, the FileSystemWatcher did'nt react if the network directory is already available. So i need to reinitialize the FileSystemWatcher in a while again. But i also heard to poll the file system isn't a good idea because it slows the cpu down. (Is it more than the FileSystemWatcher? Can anybody suggest (a good loop time for) polling?) Thank You for your suggestions...

    J M 2 Replies Last reply
    0
    • C C Scharbe

      Can any body tell me the advantages and disadvantages of both kinds to get to know if a file is in a specified directory. I have a directory in the network and a application that should work with the file took into the directory. I try to do it with a FileSystemWatcher, but the problem is, if the network connection failed, the FileSystemWatcher did'nt react if the network directory is already available. So i need to reinitialize the FileSystemWatcher in a while again. But i also heard to poll the file system isn't a good idea because it slows the cpu down. (Is it more than the FileSystemWatcher? Can anybody suggest (a good loop time for) polling?) Thank You for your suggestions...

      J Offline
      J Offline
      jmhamm
      wrote on last edited by
      #2

      You could create a thread, spins in a loop and reinitializes the FileSystemWatcher from time to time using Thread.Sleep in between. As FileSystemWatcher uses events this would effectively create a mix of polling and signaling.

      C 1 Reply Last reply
      0
      • J jmhamm

        You could create a thread, spins in a loop and reinitializes the FileSystemWatcher from time to time using Thread.Sleep in between. As FileSystemWatcher uses events this would effectively create a mix of polling and signaling.

        C Offline
        C Offline
        C Scharbe
        wrote on last edited by
        #3

        Yes i already do so, but i think: 'is this mix good?', isn't it better only to poll the file system instead using the file system watcher?

        J 1 Reply Last reply
        0
        • C C Scharbe

          Can any body tell me the advantages and disadvantages of both kinds to get to know if a file is in a specified directory. I have a directory in the network and a application that should work with the file took into the directory. I try to do it with a FileSystemWatcher, but the problem is, if the network connection failed, the FileSystemWatcher did'nt react if the network directory is already available. So i need to reinitialize the FileSystemWatcher in a while again. But i also heard to poll the file system isn't a good idea because it slows the cpu down. (Is it more than the FileSystemWatcher? Can anybody suggest (a good loop time for) polling?) Thank You for your suggestions...

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          Another downside of the FSW is that it can only be used with NTFS filesystems (FAT may be possible as well, don't know 100%). So if you're trying to watch a file on a SMB share you won't get any events.

          Regards, mav -- Black holes are the places where God divided by 0...

          1 Reply Last reply
          0
          • C C Scharbe

            Yes i already do so, but i think: 'is this mix good?', isn't it better only to poll the file system instead using the file system watcher?

            J Offline
            J Offline
            jmhamm
            wrote on last edited by
            #5

            I would think this is ok, and you can decide how often you poll, just don't do it all the time. You may use a flag for poll-only mode which reduces the polling period and disables the FileSystemWatcher, which would make it kind of universal. You could even call the same callback.

            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