<pre lang="vb"> Public Class FSWClient Public Event CiSonoFile(ByVal Sender As Object, ByVal e As System.EventArgs) Dim myFSW As New Thread(AddressOf LanciaFSW) Public Sub New() Dim watcher As New FileSystemWatcher() watcher.Path = "c:\test" watcher.IncludeSubdirectories = True watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName) watcher.Filter = "*.tif" AddHandler watcher.Created, AddressOf OnChanged watcher.EnableRaisingEvents = True 'Dim Thread1 As New System.Threading.Thread(AddressOf counter.Count) myFSW.Start() ' Wait for the user to quit the program. Console.WriteLine("Monitoring " & "c:\test") Console.WriteLine("Press 'q' to quit this console.") While Chr(Console.Read()) <> "q"c End While End Sub Sub LanciaFSW() Dim oFSWClient As New FSWClient AddHandler oFSWClient.CiSonoFile, AddressOf GoWithOCR End Sub Dim OCRisRunning As Boolean = False Sub GoWithOCR() If PathFilesList.Count > 0 AndAlso OCRisRunning = False Then RunOCR() End If End Sub Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs) ' Specify what is done when a file is changed, created, or deleted. If e.ChangeType = IO.WatcherChangeTypes.Created Then PathFilesList.Add(e.FullPath) RaiseEvent CiSonoFile(Me, New EventArgs) End If End Sub Private Sub RunOCR() Dim a As Integer Dim fileinput, fileoutput As String Do While PathFilesList.Count fileinput = PathFilesList.Item(a) Dim filein As New FileInfo(fileinput) fileoutput = "d:\test\" & filein.Name CopyFiles(fileinput, fileoutput) PathFilesList.Remove(fileinput) Loop End Sub Private Sub CopyFiles(ByVal filein As String, ByVal fileout As String) File.Copy(filein, fileout) End Sub End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)