FileSystemWatcher Class in .Net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madankarmukta
    Contributor
    • Apr 2008
    • 308

    FileSystemWatcher Class in .Net

    Hi,

    I want to use this "FileSystemWatc her " class in my project but I am not able to decide at which moment should i use it.. Can anyone help me?

    Here is the scenario.

    My Application consist of the service which is continuously running and some other modules .When my project get installed there are some files which the server continuously updates.I want to keep track of this using FileSystemWatch er.But where should i this ( use of FileSystemWatch er).. in modules or in the service..so that i will get the continuous updates about changing of the files ?

    Thanks!
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Originally posted by madankarmukta
    My Application consist of the service which is continuously running and some other modules .When my project get installed there are some files which the server continuously updates.I want to keep track of this using FileSystemWatch er.But where should i this ( use of FileSystemWatch er).. in modules or in the service..so that i will get the continuous updates about changing of the files ?

    Thanks!
    if the files are continuously updated then u could use :
    OnChanged

    For more info
    FileSystemWatch er

    Comment

    • cloud255
      Recognized Expert Contributor
      • Jun 2008
      • 427

      #3
      If you intend to watch real time changes, i suggest using your service. But do beware of access violations, these tend to happen if you are not careful with the code you use when handeling the FileSystemWatch er events, often the file is still in use when the events are raised...

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Originally posted by cloud255
        If you intend to watch real time changes, i suggest using your service. But do beware of access violations, these tend to happen if you are not careful with the code you use when handeling the FileSystemWatch er events, often the file is still in use when the events are raised...
        A good example of that is the OnCreate event. It fires as soon as new file is created:Not necessarily when it is DONE being written. So if you try to open it while it is still being written from another source.... [ugliness ensues]

        I find I never actually handle any file from OnCreate or OnChange, but rather add the file to a list to be processed, which is handled every xx seconds. If a file on the list is free then I can process it then remove from list. If not, move to the next file on the list. But that's just me.

        Comment

        Working...