Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Pause code until file fully downloaded

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob Oldfield - 04 Apr 2005 18:23 GMT
I have a situation where I need to scan a folder for downloaded files and
then process those files.  I have a file system watcher which is looking for
the creation of a file but clearly I want wait until the file is completely
downloaded before I start trying to use it.  At present I'm trying this...

Dim fi As New FileInfo(fle)
'Don't try to read while still being written
Do While fi.Length <> sz
   s = TimeOfDay.Second
   Do While TimeOfDay.Second = s
   Loop
   sz = fi.Length
Loop

...but that's going wrong on the sz=fi.length line (not immediately, but
intermittently)... telling me that the file doesn't exist.

Does anyone have a better way of approaching this?

(...and no, the sensible answer of getting the data provider to add the
creation of a 0k control file at the end of the download isn't an option.)
Robbe Morris [C# MVP] - 05 Apr 2005 02:11 GMT
you could try this:

Do While fi.length <> sz
     System.Threading.Thread.Sleep(1000)
Loop

Signature

2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx

>I have a situation where I need to scan a folder for downloaded files and
> then process those files.  I have a file system watcher which is looking
[quoted text clipped - 19 lines]
> (...and no, the sensible answer of getting the data provider to add the
> creation of a 0k control file at the end of the download isn't an option.)
Rob Oldfield - 06 Apr 2005 13:14 GMT
More efficient (and thanks for that), but still doesn't get around the
problem of it thinking that fi doesn't exist.

> you could try this:
>
[quoted text clipped - 25 lines]
> > (...and no, the sensible answer of getting the data provider to add the
> > creation of a 0k control file at the end of the download isn't an option.)
Chris Dunaway - 07 Apr 2005 22:25 GMT
What the FileSystemWatcher really needs is a FileClosed event!  But
alas, we don't have that.

One technique similar to the one Rob specified is to attempt to open
the file exclusively.  If that fails, it means the file is still in
use.

Do you control the downloading of the file?  You could send the files
with a temporary name and then rename the file to its final name and
then have the FileSystemWatcher watch for the rename event.

Good Luck

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.