File watcher with Windows service
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.
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
If e.ChangeType = WatcherChangeTypes.Created Then
File.Move(e.FullPath, upFolder & "\" & e.Name)
If e.ChangeType = WatcherChangeTypes.Deleted Then
Catch ex As Exception
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 does one operation and stops.
Any idea anyone?
Thank you in advance