Windows server Filewatcher

GregF

New member
Joined
Jan 13, 2005
Messages
1
Programming Experience
Beginner
Hello,
I'm new with windows service.
I'm trying to create service wich will move the files from one folder(Import) to another(Updated) each time when file had been droped to the Import folder.

so that's what I did:
Public WithEvents watchfolder As FileSystemWatcher
Public upFolder As String = "C:\Test_for_foldermonitoring\Updated"
Protected Overrides Sub OnStart(ByVal args() As String)
watchfolder = New System.IO.FileSystemWatcher
watchfolder.Path = "C:\Test_for_foldermonitoring\Import"
AddHandler watchfolder.Changed, AddressOf FolderMonitor
AddHandler watchfolder.Created, AddressOf FolderMonitor
AddHandler watchfolder.Deleted, AddressOf FolderMonitor

watchfolder.EnableRaisingEvents = True
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
End Sub
Public Sub FolderMonitor(ByVal source As Object, ByVal e As FileSystemEventArgs)
' Dim Mypath As String = "C:\Test_for_foldermonitoring\Import"
' Dim MynewPath As String = "C:\Test_for_foldermonitoring\Updated"
If e.ChangeType = WatcherChangeTypes.Changed Then

End If
Try
If e.ChangeType = WatcherChangeTypes.Created Then
File.Move(e.FullPath, upFolder & "\" & e.Name)

End If
If e.ChangeType = WatcherChangeTypes.Deleted Then
End If
Catch ex As Exception


End Try

End Sub

looks pretty easy and works fine when i try it with application or dll,but...(it always a "but" :() when i install it as windows service:
1.It's not working properly with "multifiles drop".
2.It works as soon i started service ,did one operation and stops.
Any idea anyone?
Thank you in advance
 
Top Bottom