Question FileSystemWatcher_Created advice

dumdum

New member
Joined
Jun 28, 2010
Messages
1
Programming Experience
Beginner
hi

I'm pretty new to VB.net and looking for some advice, any pointers will be much appreciated

I'm writing a small application that downloads some files over ftp, the incoming directory is monitored by FileSystemWatcher_Created, on creation I want to extract some text from the file and call another application with the text as parameters

the problem I have is the FileSystemWatcher_Created procedure is triggered before the file has finished downloading, I could download it elsewhere and move into the monitored directory but some of the files may be quite large and Im wondering if there is an efficient way of waiting until the file is ready?

along the same lines what is the best way to queue the tasks as there can be many files coming it at one time, I've looked at threading but would that be suitable for such a task as there will still be a bottleneck at the application called by FileSystemWatcher_Created ?

heres an outline of what im doing:


VB.NET:
Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created

        'read text file        
        text = [read the text file here]
        
        'incoming class calls the application with parameters
        Dim incoming As New incomingClass()
        incoming.parameters = text        
        incoming.incoming()
 
The problem with FTP is that when the file starts downloading a stub file is created and then all of the data streamed to the stub. The creation of the stub causes the event to fire even though it's a 0 byte file.

In this case I'd recommend creating a loop where you check every n seconds to see if you can open it with exclusive access. Once you can do that you know FTP has released it.
 
Back
Top