Opinion on how best to wait for a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • john bailo

    Opinion on how best to wait for a file

    I'm writing a program to monitor the operation of a process.

    Part of the process involves trigging a method,
    then waiting for the creation of a flag file. I
    want my code to pause at that point.

    How would you recomment waiting and monitoring.
    I can think of two ways:

    0. Start a timer.
    1. Raise an event to check for File.Exists("")
    2. If File.Exists then Timer.Enabled=f alse.


    Or

    Do a while loop, with while(File.Exis ts())

    What do you guys recommend?



  • Robert Jeppesen

    #2
    Re: Opinion on how best to wait for a file

    You have the added option of using a FileSystemWatch er and receive an event
    when stuff happens in 'Watched' folders. Details are in MSDN.

    --
    Robert Jeppesen
    robert.jeppesen %at%durius-dot-se


    "john bailo" <jbailo@vestcom .com> wrote in message news:775a4c308d d9257129c8fff27 5e823b2@news.te ranews.com...[color=blue]
    > I'm writing a program to monitor the operation of a process.
    >
    > Part of the process involves trigging a method,
    > then waiting for the creation of a flag file. I
    > want my code to pause at that point.
    >
    > How would you recomment waiting and monitoring.
    > I can think of two ways:
    >
    > 0. Start a timer.
    > 1. Raise an event to check for File.Exists("")
    > 2. If File.Exists then Timer.Enabled=f alse.
    >
    >
    > Or
    >
    > Do a while loop, with while(File.Exis ts())
    >
    > What do you guys recommend?
    >
    >
    >[/color]


    Comment

    • Alvin Bruney

      #3
      Re: Opinion on how best to wait for a file

      The filesystemwatch er is known to have issues because of the underlying OS
      which doesn't always notify the listener. Proceed with caution.

      "Robert Jeppesen" <robert.jeppese n(#)durius.se> wrote in message
      news:#u5fAWrjDH A.3256@tk2msftn gp13.phx.gbl...[color=blue]
      > You have the added option of using a FileSystemWatch er and receive an[/color]
      event[color=blue]
      > when stuff happens in 'Watched' folders. Details are in MSDN.
      >
      > --
      > Robert Jeppesen
      > robert.jeppesen %at%durius-dot-se
      >
      >
      > "john bailo" <jbailo@vestcom .com> wrote in message[/color]
      news:775a4c308d d9257129c8fff27 5e823b2@news.te ranews.com...[color=blue][color=green]
      > > I'm writing a program to monitor the operation of a process.
      > >
      > > Part of the process involves trigging a method,
      > > then waiting for the creation of a flag file. I
      > > want my code to pause at that point.
      > >
      > > How would you recomment waiting and monitoring.
      > > I can think of two ways:
      > >
      > > 0. Start a timer.
      > > 1. Raise an event to check for File.Exists("")
      > > 2. If File.Exists then Timer.Enabled=f alse.
      > >
      > >
      > > Or
      > >
      > > Do a while loop, with while(File.Exis ts())
      > >
      > > What do you guys recommend?
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Robert Jeppesen

        #4
        Re: Opinion on how best to wait for a file

        Yes, I heard of that pre-2003. Is this still an issue in Framework 1.1?

        --
        Robert Jeppesen
        robert.jeppesen %at%durius-dot-se


        "Alvin Bruney" <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote in message news:e3hFjcrjDH A.2732@TK2MSFTN GP11.phx.gbl...[color=blue]
        > The filesystemwatch er is known to have issues because of the underlying OS
        > which doesn't always notify the listener. Proceed with caution.
        >
        > "Robert Jeppesen" <robert.jeppese n(#)durius.se> wrote in message
        > news:#u5fAWrjDH A.3256@tk2msftn gp13.phx.gbl...[color=green]
        > > You have the added option of using a FileSystemWatch er and receive an[/color]
        > event[color=green]
        > > when stuff happens in 'Watched' folders. Details are in MSDN.
        > >
        > > --
        > > Robert Jeppesen
        > > robert.jeppesen %at%durius-dot-se
        > >
        > >
        > > "john bailo" <jbailo@vestcom .com> wrote in message[/color]
        > news:775a4c308d d9257129c8fff27 5e823b2@news.te ranews.com...[color=green][color=darkred]
        > > > I'm writing a program to monitor the operation of a process.
        > > >
        > > > Part of the process involves trigging a method,
        > > > then waiting for the creation of a flag file. I
        > > > want my code to pause at that point.
        > > >
        > > > How would you recomment waiting and monitoring.
        > > > I can think of two ways:
        > > >
        > > > 0. Start a timer.
        > > > 1. Raise an event to check for File.Exists("")
        > > > 2. If File.Exists then Timer.Enabled=f alse.
        > > >
        > > >
        > > > Or
        > > >
        > > > Do a while loop, with while(File.Exis ts())
        > > >
        > > > What do you guys recommend?
        > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Bryan Martin

          #5
          Re: Opinion on how best to wait for a file

          Do a groups.google.c om search on "systemfilewatc her" namespace.

          Bryan
          "john bailo" <jbailo@vestcom .com> wrote in message
          news:775a4c308d d9257129c8fff27 5e823b2@news.te ranews.com...[color=blue]
          > I'm writing a program to monitor the operation of a process.
          >
          > Part of the process involves trigging a method,
          > then waiting for the creation of a flag file. I
          > want my code to pause at that point.
          >
          > How would you recomment waiting and monitoring.
          > I can think of two ways:
          >
          > 0. Start a timer.
          > 1. Raise an event to check for File.Exists("")
          > 2. If File.Exists then Timer.Enabled=f alse.
          >
          >
          > Or
          >
          > Do a while loop, with while(File.Exis ts())
          >
          > What do you guys recommend?
          >
          >
          >[/color]


          Comment

          • Tim Stephenson

            #6
            Re: Opinion on how best to wait for a file

            The Filesystemwatch er object is designed to do this, and will raise an event
            when a file is created / modified / deleted within a specicified directory.
            Get your code to start the watcher, then call the code you need to run once
            the file's created in the handler for the appropriate event.

            --

            Regards

            Tim Stephenson MCSD.NET
            Charted MCAD & MCSD.NET Early Achiever


            "john bailo" <jbailo@vestcom .com> wrote in message
            news:775a4c308d d9257129c8fff27 5e823b2@news.te ranews.com...[color=blue]
            > I'm writing a program to monitor the operation of a process.
            >
            > Part of the process involves trigging a method,
            > then waiting for the creation of a flag file. I
            > want my code to pause at that point.
            >
            > How would you recomment waiting and monitoring.
            > I can think of two ways:
            >
            > 0. Start a timer.
            > 1. Raise an event to check for File.Exists("")
            > 2. If File.Exists then Timer.Enabled=f alse.
            >
            >
            > Or
            >
            > Do a while loop, with while(File.Exis ts())
            >
            > What do you guys recommend?
            >
            >
            >[/color]


            Comment

            Working...