I've put off posting this one for a while, as I know related subjects hav been discussed, but I just can't seem to get it working.
I have a service with a FileSystemWatcher:
What I'm trying to do is call the loadRHviaDirectoryWatcher once to process any files that are already there. Trouble is, that processing often takes hours, and OnStart has to finish in 30 seconds or the service fails to start.Code:Public Class RightHemisphereLoader Private watcher As IO.FileSystemWatcher Private zipfile As ICSharpCode.SharpZipLib.Zip.ZipFile Private utils As New RHUtils.RHUtils Protected Overrides Sub OnStart(ByVal args() As String) Try ' Add code here to start your service. This method should set things ' in motion so your service can do its work. 'At this point we've processed what's there. 'Set up our watcher for LCA data watcher = New IO.FileSystemWatcher watcher.Path = utils.setting("InputDirectory") watcher.Filter = "*.zip" watcher.IncludeSubdirectories = True watcher.NotifyFilter = NotifyFilters.FileName AddHandler watcher.Created, AddressOf loadRHviaDirectoryWatcher 'Begin watching watcher.EnableRaisingEvents = True utils.WriteLog("Service and directory watcher started.", "OnStart", "Info") 'In case there's stuff there, clean and raise the event cleanDir(utils.setting("WorkingDirectory")) Catch ex As Exception utils.WriteLog(ex.Message(), "OnStart", "ERROR") End Try End Sub
I've tried creating a custom event that loadRHviaDirectoryWatcher handles and raising it, but then the AddHandler line complains.
How is this best accomplished? Thanks!




Reply With Quote