FileSystemWatcher Windows Service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig Thompson

    FileSystemWatcher Windows Service

    I've attempted to write a windows service that creates one FileSystemWatch er
    for each entry in a XML config file. Everything start perfrectly and runs
    as I expect for about 5 minutes and then after that the FileSystemWatch ers
    seem to stop monitoring... My theory is that for some reason the Garbage
    Collector is trashing my FileSystemWatch ers.

    Another clue to my situation is that I just took my service and made it into
    a windows form application and it's been running overnight without any
    problems. What am I overlooking? Can anyone point me in the right
    direction?

    Thanks,

    Craig


  • Fakher Halim

    #2
    Re: FileSystemWatch er Windows Service

    Craig,
    I have been using watcher in windows service. Sometimes when you start a
    program from the watching event and that program breaks, the whole watcher
    service appear to break. If you attach the debugger to windows service, you
    would find out that the main window service thread would be stuck in some
    other part of program, thus ignoring further watcher interrupts. To make
    sure all watcher events are always handled, I write a very small process
    which just pushes the required info in SQL Server table and relinquish the
    control back to listener. The time consuming main program then looks in the
    SQL Server table, pops off the watcher generated rows, and process them at
    its Owen convenience reducing the risk of overlooking watcher event.

    Fakher Halim

    "Craig Thompson >" <cthompson@trcs olutions<NO Spam> wrote in message
    news:OYV2Rj89DH A.4020@TK2MSFTN GP09.phx.gbl...[color=blue]
    > I've attempted to write a windows service that creates one[/color]
    FileSystemWatch er[color=blue]
    > for each entry in a XML config file. Everything start perfrectly and runs
    > as I expect for about 5 minutes and then after that the FileSystemWatch ers
    > seem to stop monitoring... My theory is that for some reason the Garbage
    > Collector is trashing my FileSystemWatch ers.
    >
    > Another clue to my situation is that I just took my service and made it[/color]
    into[color=blue]
    > a windows form application and it's been running overnight without any
    > problems. What am I overlooking? Can anyone point me in the right
    > direction?
    >
    > Thanks,
    >
    > Craig
    >
    >[/color]


    Comment

    • Craig Thompson

      #3
      Re: FileSystemWatch er Windows Service

      Fakher,
      Thanks for the response and the advice. I'll give it a shot...
      Craig


      "Fakher Halim" <fakher@msn.com > wrote in message
      news:Oo5oXt89DH A.3880@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Craig,
      > I have been using watcher in windows service. Sometimes when you start a
      > program from the watching event and that program breaks, the whole watcher
      > service appear to break. If you attach the debugger to windows service,[/color]
      you[color=blue]
      > would find out that the main window service thread would be stuck in some
      > other part of program, thus ignoring further watcher interrupts. To make
      > sure all watcher events are always handled, I write a very small process
      > which just pushes the required info in SQL Server table and relinquish the
      > control back to listener. The time consuming main program then looks in[/color]
      the[color=blue]
      > SQL Server table, pops off the watcher generated rows, and process them at
      > its Owen convenience reducing the risk of overlooking watcher event.
      >
      > Fakher Halim
      >
      > "Craig Thompson >" <cthompson@trcs olutions<NO Spam> wrote in message
      > news:OYV2Rj89DH A.4020@TK2MSFTN GP09.phx.gbl...[color=green]
      > > I've attempted to write a windows service that creates one[/color]
      > FileSystemWatch er[color=green]
      > > for each entry in a XML config file. Everything start perfrectly and[/color][/color]
      runs[color=blue][color=green]
      > > as I expect for about 5 minutes and then after that the[/color][/color]
      FileSystemWatch ers[color=blue][color=green]
      > > seem to stop monitoring... My theory is that for some reason the[/color][/color]
      Garbage[color=blue][color=green]
      > > Collector is trashing my FileSystemWatch ers.
      > >
      > > Another clue to my situation is that I just took my service and made it[/color]
      > into[color=green]
      > > a windows form application and it's been running overnight without any
      > > problems. What am I overlooking? Can anyone point me in the right
      > > direction?
      > >
      > > Thanks,
      > >
      > > Craig
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Craig Thompson

        #4
        Re: FileSystemWatch er Windows Service

        Just to follow-up for anyone who runs into this problem in the future...
        Fakher's suggestion worked. I changed my service to only execute a stored
        procedure that writes a record to a SQL table when a FileSystemWatch er event
        is triggered. Then periodically, I have another thread on the service that
        looks at this table for new files to process. This seems to have freed up
        the FileSystemWatch er thread and my service does not mysteriously stop
        anymore...

        Craig

        "Craig Thompson >" <cthompson@trcs olutions<NO Spam> wrote in message
        news:%23K1$L789 DHA.1768@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > Fakher,
        > Thanks for the response and the advice. I'll give it a shot...
        > Craig
        >
        >
        > "Fakher Halim" <fakher@msn.com > wrote in message
        > news:Oo5oXt89DH A.3880@TK2MSFTN GP11.phx.gbl...[color=green]
        > > Craig,
        > > I have been using watcher in windows service. Sometimes when you start a
        > > program from the watching event and that program breaks, the whole[/color][/color]
        watcher[color=blue][color=green]
        > > service appear to break. If you attach the debugger to windows service,[/color]
        > you[color=green]
        > > would find out that the main window service thread would be stuck in[/color][/color]
        some[color=blue][color=green]
        > > other part of program, thus ignoring further watcher interrupts. To make
        > > sure all watcher events are always handled, I write a very small process
        > > which just pushes the required info in SQL Server table and relinquish[/color][/color]
        the[color=blue][color=green]
        > > control back to listener. The time consuming main program then looks in[/color]
        > the[color=green]
        > > SQL Server table, pops off the watcher generated rows, and process them[/color][/color]
        at[color=blue][color=green]
        > > its Owen convenience reducing the risk of overlooking watcher event.
        > >
        > > Fakher Halim
        > >
        > > "Craig Thompson >" <cthompson@trcs olutions<NO Spam> wrote in message
        > > news:OYV2Rj89DH A.4020@TK2MSFTN GP09.phx.gbl...[color=darkred]
        > > > I've attempted to write a windows service that creates one[/color]
        > > FileSystemWatch er[color=darkred]
        > > > for each entry in a XML config file. Everything start perfrectly and[/color][/color]
        > runs[color=green][color=darkred]
        > > > as I expect for about 5 minutes and then after that the[/color][/color]
        > FileSystemWatch ers[color=green][color=darkred]
        > > > seem to stop monitoring... My theory is that for some reason the[/color][/color]
        > Garbage[color=green][color=darkred]
        > > > Collector is trashing my FileSystemWatch ers.
        > > >
        > > > Another clue to my situation is that I just took my service and made[/color][/color][/color]
        it[color=blue][color=green]
        > > into[color=darkred]
        > > > a windows form application and it's been running overnight without any
        > > > problems. What am I overlooking? Can anyone point me in the right
        > > > direction?
        > > >
        > > > Thanks,
        > > >
        > > > Craig
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...