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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Code behind File System Watcher

Code behind File System Watcher

Scheduled Pinned Locked Moved C#
algorithmsquestion
5 Posts 4 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.
  • T Offline
    T Offline
    thomforum
    wrote on last edited by
    #1

    Hello All -- I am trying to watch a folder for any changes to it. I am integrating my code with a CAD application to make modifications to a model depending on the changes occuring in the watched folder. So, to watch a folder I make use of filesystemwatcher. But when I do that, there are some problems occuring with CAD Application. Without filesystemwatcher this works perfectly fine. Now I use timer to see any changes in that folder. Searching over the net, many told that there are some bugs in filesystemwatcher. Does anybody have the code that is behind FileSystemWatcher ? Thanks, Thomas.

    N L B 3 Replies Last reply
    0
    • T thomforum

      Hello All -- I am trying to watch a folder for any changes to it. I am integrating my code with a CAD application to make modifications to a model depending on the changes occuring in the watched folder. So, to watch a folder I make use of filesystemwatcher. But when I do that, there are some problems occuring with CAD Application. Without filesystemwatcher this works perfectly fine. Now I use timer to see any changes in that folder. Searching over the net, many told that there are some bugs in filesystemwatcher. Does anybody have the code that is behind FileSystemWatcher ? Thanks, Thomas.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      How is the FileSystemWatching affecting the application? Unless you are modifying the files in some way there should be no issues, it simply notifies you of a change.


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • T thomforum

        Hello All -- I am trying to watch a folder for any changes to it. I am integrating my code with a CAD application to make modifications to a model depending on the changes occuring in the watched folder. So, to watch a folder I make use of filesystemwatcher. But when I do that, there are some problems occuring with CAD Application. Without filesystemwatcher this works perfectly fine. Now I use timer to see any changes in that folder. Searching over the net, many told that there are some bugs in filesystemwatcher. Does anybody have the code that is behind FileSystemWatcher ? Thanks, Thomas.

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

        Hi, I'm not aware of any bugs in FileSystemWatcher class. There are a few things you may need to know about it though: - one file operation may result in several FSW chanes being triggered; e.g. a big write may touch several sectors and clusters; more info is here: FileSystemWatcher - Pure Chaos (Part 1 of 2)[^] - there is no "file operation done" signal; so if your app needs to read a newly written file, a simple write event isn't sufficient. A common solution is to use another (small) file as a signal: watch for file B being created; create big file A; when done create small file B causing a signal. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        1 Reply Last reply
        0
        • T thomforum

          Hello All -- I am trying to watch a folder for any changes to it. I am integrating my code with a CAD application to make modifications to a model depending on the changes occuring in the watched folder. So, to watch a folder I make use of filesystemwatcher. But when I do that, there are some problems occuring with CAD Application. Without filesystemwatcher this works perfectly fine. Now I use timer to see any changes in that folder. Searching over the net, many told that there are some bugs in filesystemwatcher. Does anybody have the code that is behind FileSystemWatcher ? Thanks, Thomas.

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Be aware that some applications strangely create an empty file first, and a few moments later on they open it for writing and write the contents. FileSystemWatcher is very fast, and you may happen to move the file away when it is still empty - if the other application then tries to open it for writing, that application could be stupid enough to cause an exception. Try to create your own watcher class by encapsulating FileSystemWatcher and dealing with empty files and files still being written by the other application, and some more strange things specific of that CAD application.

          T 1 Reply Last reply
          0
          • B Bernhard Hiller

            Be aware that some applications strangely create an empty file first, and a few moments later on they open it for writing and write the contents. FileSystemWatcher is very fast, and you may happen to move the file away when it is still empty - if the other application then tries to open it for writing, that application could be stupid enough to cause an exception. Try to create your own watcher class by encapsulating FileSystemWatcher and dealing with empty files and files still being written by the other application, and some more strange things specific of that CAD application.

            T Offline
            T Offline
            thomforum
            wrote on last edited by
            #5

            All -- I thank everybody for dropping in and letting me know the various aspects. I still couldnt figure out why the trouble is happening. I can successfully watch a folder and get the file changed/created/deleted notifications, but when I try opening a file in UG(Unigraphics CAD App) (The next line in code is opening a file in a CAD Application) it throws out an error "Attempt to read or write protected memory." Hence I am forced to use timer. But timer is not a true solution. Probably I can send in the code and a small file to be opened in CAD, but I am dubious, whether somebody will have the CAD App. Code : C# CAD APP: UG NX 5 Thanks and Cheers Thomas

            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