Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 13th, 2005, 01:45 PM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default File watcher with Windows service

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 does one operation and stops.
Any idea anyone?
Thank you in advance


Reply With Quote
  #2 (permalink)  
Old February 1st, 2005, 09:39 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: York, , United Kingdom.
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

One idea is that the Buffer of the FileSystemWatcher is quite small and easily gets full; therefore only watch for one type of file with each one.

In some cases, I'd recomment using a timer control and checking the contents of the folder on each tick; if you're just waiting for files to arrive in a directory, use the 'create date' property. FileSystemWatcher isn't really very big or robust.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows service File Search for Mapped Drives vinod_yadav1919 C# 4 August 3rd, 2008 09:48 AM
Help for directory watcher with Windows Service abhisjek-patel VB.NET 0 November 13th, 2007 02:22 AM
windows service for writting a text file srkarthik_82 General .NET 0 January 4th, 2007 01:31 AM
WMI Event Watcher for Service Monitoring deepumi SQL Server 2005 1 June 2nd, 2006 05:08 AM
File System Watcher hugh@kmcnetwork.com VB.NET 12 June 4th, 2004 07:29 AM



All times are GMT -4. The time now is 01:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.