Robust solution for processing files in a folder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Philip Wagenaar

    #1

    Robust solution for processing files in a folder

    Hello,

    I am writing an application that processes xml files that are stored in a
    folder. The application picks up the files in a folder, processes them and
    then deletes them.

    What is the best approach on loading the xml files from the folder into my
    application?

    At the moment I am using the System.IO.FileS ystemWatcher to monitor files
    that are created in the folder (created is same as copied to) and then I add
    the filename to a Queue object. This has as drawback that if files are in the
    folder before the application is started I have to load the into my
    application manually.

    If I have to write code to load the files that are already in folder before
    the FileSystemWatch er becomes active, why would I even use the
    FileSystemWatch er? I could use a timer and scan the directory on every
    Timer.Elapsed.

    I need a robust solution for 'monitoring' a folder and processing the files
    in a Windows Forms application.

    Philip Wagenaar
  • AMercer

    #2
    RE: Robust solution for processing files in a folder

    > I need a robust solution for 'monitoring' a folder and processing the files[color=blue]
    > in a Windows Forms application.[/color]

    I would use both FileSystemWatch er and a Timer. I would arrange for the
    FileSystemWatch er to enable the Timer with interval=1 (ie an immediate tick)
    whenever it sees the kind of change you want. I would arrange for the Timer
    tick code to process all files it finds in the folder. If the Timer tick
    code finds nothing in the folder, increase the interval up to a maximum,
    something like:
    interval *= 10
    if interval >10000 then interval = 10000 ' 10 sec max
    If the Timer tick code finds at least one file in the folder, decrease the
    interval:
    interval = 1

    This design achieves the following. When no files are arriving, you will be
    lightweight. When no files are arriving, you will periodically take a peek
    at the folder anyway, and thus you are robust in the event of a
    FileSystemWatch er failure. When files are arriving, you will get them all
    without fail every time. FileSystemWatch er use is as simple as it can be, ie
    when event tweak a timer, and nothing else.

    In case you haven't noticed, I have some mistrust of FileSystemWatch er. I
    believe its underlying technology is api ReadDirectoryCh angesW, and some
    years ago I had some difficulties with its reliability. Today, perhaps my
    mistrust is unwarranted, but old attitudes are hard to change.

    Comment

    Working...