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. Visual Basic
  4. Question regarding filesystemwatcher and existing files

Question regarding filesystemwatcher and existing files

Scheduled Pinned Locked Moved Visual Basic
questiondatabaseregex
6 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.
  • J Offline
    J Offline
    Jon_Boy
    wrote on last edited by
    #1

    I'm working on an app that utilizes a filesystemwatcher to detect for a particular type of file. When the watcher is running, everything is fine. The watcher correctly picks up new files. However, the app needs to support being paused and restarted. So, if the app is paused, files are then copied into the directory and the watcher is restarted - it doesn't pick up the existing files even though they match the filter. I realize the watcher wouldn't trigger the created or modified events, but is there a way to make the watcher to pick up these files, or do I just need to code around this? Just wanted to make sure I wasn't overlooking something with the filewatcher itself.

    "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

    D 1 Reply Last reply
    0
    • J Jon_Boy

      I'm working on an app that utilizes a filesystemwatcher to detect for a particular type of file. When the watcher is running, everything is fine. The watcher correctly picks up new files. However, the app needs to support being paused and restarted. So, if the app is paused, files are then copied into the directory and the watcher is restarted - it doesn't pick up the existing files even though they match the filter. I realize the watcher wouldn't trigger the created or modified events, but is there a way to make the watcher to pick up these files, or do I just need to code around this? Just wanted to make sure I wasn't overlooking something with the filewatcher itself.

      "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      The watcher will only do things it is designed for. It will not detect files that have been added while the watcher is paused. Why pause the App? why not leave it running and just handle the events while the file copy operation is in progress. system.io.filesystemwatcher[^]

      Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

      J 1 Reply Last reply
      0
      • D DaveAuld

        The watcher will only do things it is designed for. It will not detect files that have been added while the watcher is paused. Why pause the App? why not leave it running and just handle the events while the file copy operation is in progress. system.io.filesystemwatcher[^]

        Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

        J Offline
        J Offline
        Jon_Boy
        wrote on last edited by
        #3

        I don't come up with the design requirements, I'm just tasked with "getting it done". Just checking to make sure that the filewatcher doesn't support this action. Thanks though.

        "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

        I 1 Reply Last reply
        0
        • J Jon_Boy

          I don't come up with the design requirements, I'm just tasked with "getting it done". Just checking to make sure that the filewatcher doesn't support this action. Thanks though.

          "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

          I Offline
          I Offline
          Ian Shlasko
          wrote on last edited by
          #4

          Well, here's an alternative solution... Instead of pausing the FSW, pause the handler. When you get an event, check to see whether your handler is "paused"... If so, stick the event in a Queue instead. When unpausing, process the Queue first.

          Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

          J 1 Reply Last reply
          0
          • I Ian Shlasko

            Well, here's an alternative solution... Instead of pausing the FSW, pause the handler. When you get an event, check to see whether your handler is "paused"... If so, stick the event in a Queue instead. When unpausing, process the Queue first.

            Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

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

            Admittedly, I've never heard of pausing a handler. Could you point me in the right direction?

            "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

            I 1 Reply Last reply
            0
            • J Jon_Boy

              Admittedly, I've never heard of pausing a handler. Could you point me in the right direction?

              "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

              I Offline
              I Offline
              Ian Shlasko
              wrote on last edited by
              #6

              Something like this (pseudocode):

              Class Watcher

              Private System.IO.FileSystemWatcher
              Private Bool IsPaused
              Private Queue

              Public Sub Pause()
              IsPaused = true
              End Sub

              Public Sub UnPause()
              While Queue is not empty
              ProcessFSWEvent(next item in queue)
              IsPaused = false
              End Sub

              Private Sub FileSystemWatcherEventHandler(sender, eventargs)
              If IsPaused Then
              Add eventargs to Queue
              Else
              ProcessFSWEvent(eventargs)
              End Sub

              Private Sub ProcessFSWEvent(eventargs)
              Do whatever you'd normally do with the event
              End Sub

              Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

              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