Public Class Form1
Dim PublicWaitUntil As New Date
Private Sub Me_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.Show()
Dim SourceFolderText As String = "C:\Temp\Source\"
Do
Dim SourceFolderFileSystemWatcher As New IO.FileSystemWatcher
SourceFolderFileSystemWatcher.Path = SourceFolderText
SourceFolderFileSystemWatcher.Filter = "*.*"
SourceFolderFileSystemWatcher.NotifyFilter = (IO.NotifyFilters.CreationTime Or IO.NotifyFilters.LastWrite Or IO.NotifyFilters.LastAccess Or IO.NotifyFilters.FileName Or IO.NotifyFilters.LastWrite Or IO.NotifyFilters.Size)
AddHandler SourceFolderFileSystemWatcher.Changed, AddressOf SourceFolderFileSystemWatcher_Changed
AddHandler SourceFolderFileSystemWatcher.Created, AddressOf SourceFolderFileSystemWatcher_Changed
AddHandler SourceFolderFileSystemWatcher.Renamed, AddressOf SourceFolderFileSystemWatcher_Changed
AddHandler SourceFolderFileSystemWatcher.Deleted, AddressOf SourceFolderFileSystemWatcher_Changed
SourceFolderFileSystemWatcher.EnableRaisingEvents = True
Paws(99999)
Loop
End Sub
Public Sub Paws(ByVal Milliseconds As ULong)
PublicWaitUntil = Now + New TimeSpan(0, 0, 0, 0, Milliseconds)
Dim RemainingTimeSpan As New TimeSpan
While Now < PublicWaitUntil
Threading.Thread.Sleep(18)
Application.DoEvents()
End While
End Sub
Public Sub SourceFolderFileSystemWatcher_Changed()
PublicWaitUntil = Now
'Code to run when source folder changes.
End Sub
End Class
Tips and tricks for .NET using ASP and VB code.
Reliably watch for new files in a folder
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment