locked
Execute code every 5 seconds RRS feed

  • Question

  • User-1584441573 posted

    I am developing utlity that needs to listen to ftp folder for received files. How can I set up a loop itteration that will execute the code  

    FindFiles() 'Has to be called constantly to look for new files.
     checking if there are files on that folder every 5 seconds or so.

    Can someone help with a starter code.

     Any help will be appreciated.

     Thank you.

    Tuesday, August 19, 2008 4:17 PM

Answers

  • User1330954201 posted

    I'd go with the above suggestion of a windows service. You could use a FileSystemWatcher event or you could use a Timer to scan the directory every 5 seconds.

    Example Code :-

     

    Imports
    System.Threading

    'Set the timer.

    Dim m_scheduledjobsautoevent As New AutoResetEvent(False)

    'Be aware that FindFiles will run on a new thread each time it is called

    Dim m_scheduledjobscallback As TimerCallback = AddressOf FindFiles

    'Start in 5 seconds, repeat every 5 seconds

    Dim m_scheduledjobstimer As Timer = _

    New Timer(m_scheduledjobscallback, m_scheduledjobsautoevent, 5000, 5000)

    Private Sub FindFiles(ByVal state As Object)

    'Find those files

    End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 20, 2008 10:39 AM

All replies

  • User599164775 posted

    There is a class name FileSystemWatcher, which allows you to keep watch on any folder.

     have a look at this link, its server which continusly watching and producing report

    http://www.codeproject.com/KB/cs/filewatcherwinservicecsha.aspx

    Hope this helps you.

    Tuesday, August 19, 2008 11:02 PM
  • User-319574463 posted

     For code to be running so as to be able to poll every 5 seconds, normally means writing a windows service.

    What language are you writing in?

    Where is your site to be hosted?

    Wednesday, August 20, 2008 2:54 AM
  • User-1584441573 posted

    I am using vb.net I tried the FileWathcher and Time object, but it doesn't work on console app only on windows forms. 

    Wednesday, August 20, 2008 9:52 AM
  • User1330954201 posted

    I'd go with the above suggestion of a windows service. You could use a FileSystemWatcher event or you could use a Timer to scan the directory every 5 seconds.

    Example Code :-

     

    Imports
    System.Threading

    'Set the timer.

    Dim m_scheduledjobsautoevent As New AutoResetEvent(False)

    'Be aware that FindFiles will run on a new thread each time it is called

    Dim m_scheduledjobscallback As TimerCallback = AddressOf FindFiles

    'Start in 5 seconds, repeat every 5 seconds

    Dim m_scheduledjobstimer As Timer = _

    New Timer(m_scheduledjobscallback, m_scheduledjobsautoevent, 5000, 5000)

    Private Sub FindFiles(ByVal state As Object)

    'Find those files

    End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 20, 2008 10:39 AM
  • User-1584441573 posted

    Thanks that worked 

    Wednesday, August 20, 2008 1:50 PM