"Philip Wagenaar" <ph************ *@online.nospam > wrote in message news:5F******** *************** ***********@mic rosoft.com...
You mean working with threads?
Is it possible to post a sample?
I found my original proof of concept code. It was implemented as a Windows Service. Most of the concepts were obtained from Google
searches, etc.
=============== =============== =============== ====
Imports System
Imports System.Threadin g
Module General
Public goFIFO As New Collections.Que ue
Public gblnStopThreads As Boolean
Public gstrSourceDir As String
Public gstrDestination Dir As String
Public goLogger As New CLog
Public goEventlog As EventLog
Public gintIdle As Integer
Public gintInterval As Integer
End Module
-----------------------------
Imports System.Threadin g
Imports System.io
Public Class WorkerThread
Public Shared Sub ProcessFiles()
Dim e As Object
Dim strFilePath As String
Dim strDestDir As String
Do Until gblnStopThreads And (goFIFO.Count = 0)
Try
If goFIFO.Count > 0 Then
e = goFIFO.Dequeue
If TypeOf e Is RenamedEventArg s Then
Dim strOldName As String = CType(e, RenamedEventArg s).OldFullPath. Replace(gstrSou rceDir, gstrDestination Dir)
strDestDir = CType(e, RenamedEventArg s).FullPath.Rep lace(gstrSource Dir, gstrDestination Dir)
Rename(strOldNa me, strDestDir)
ElseIf TypeOf e Is FileSystemEvent Args Then
strFilePath = CType(e, FileSystemEvent Args).FullPath
strDestDir = strFilePath.Rep lace(gstrSource Dir, gstrDestination Dir)
If (GetAttr(strFil ePath) And FileAttribute.D irectory) = FileAttribute.D irectory Then
If Not Directory.Exist s(strDestDir) Then
strFilePath = strFilePath
strDestDir = strFilePath.Rep lace(gstrSource Dir, gstrDestination Dir)
Directory.Creat eDirectory(strD estDir)
End If
ElseIf New FileInfo(strDes tDir).Directory .Exists = False Then
strFilePath = strFilePath
strDestDir = strFilePath.Rep lace(gstrSource Dir, gstrDestination Dir)
Directory.Creat eDirectory(Path .GetDirectoryNa me(strDestDir))
End If
If Not (GetAttr(strFil ePath) And FileAttribute.D irectory) = FileAttribute.D irectory Then
FileCopy(strFil ePath, strDestDir)
End If
End If
Thread.Sleep(gi ntInterval)
Else
Thread.Sleep(gi ntIdle)
End If
Catch ex As Exception
goEventlog.Writ eEntry(ex.Messa ge, EventLogEntryTy pe.Error)
End Try
Loop
End Sub
End Class
-----------------------------
Imports System.ServiceP rocess
Imports System
Imports System.Threadin g
Imports System.io
Imports Microsoft.Win32
Public Class MirrorService
Inherits System.ServiceP rocess.ServiceB ase
Private WithEvents moWatcher As FileSystemWatch er
Protected Overrides Sub OnStart(ByVal args() As String)
Me.AutoLog = True
goEventlog = Me.EventLog()
Process.GetCurr entProcess().Pr iorityClass = ProcessPriority Class.High
gstrSourceDir = "C:\WatcherTest \Source"
gstrDestination Dir = "F:\WatcherTest \Destination"
gintIdle = 5000
gintInterval = 100
Dim oWorker As New WorkerThread
Dim oWorkerThread As New Thread(New ThreadStart(Add ressOf oWorker.Process Files))
' Start the thread.
oWorkerThread.S tart()
moWatcher = New FileSystemWatch er
moWatcher.Inter nalBufferSize = 16384
moWatcher.Path = gstrSourceDir
moWatcher.Inclu deSubdirectorie s = True
moWatcher.Enabl eRaisingEvents = True
End Sub
Protected Overrides Sub OnStop()
gblnStopThreads = True
End Sub
Private Sub moWatcher_Creat edOrChanged(ByV al sender As Object, ByVal e As System.IO.FileS ystemEventArgs) Handles moWatcher.Chang ed,
moWatcher.Creat ed
Try
If e.ChangeType <> WatcherChangeTy pes.Deleted Then
goFIFO.Enqueue( e)
End If
Catch ex As Exception
goEventlog.Writ eEntry(ex.Messa ge, EventLogEntryTy pe.Error)
End Try
End Sub
Private Sub moWatcher_Renam ed(ByVal sender As Object, ByVal e As System.IO.Renam edEventArgs) Handles moWatcher.Renam ed
goFIFO.Enqueue( CType(e, RenamedEventArg s))
End Sub
End Class
=============== =============== =============== ======
Sorry that the cut and paste lost the formatting. I hope this helps.
==
Al Reid