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 / .NET Framework / New Users / April 2006

Tip: Looking for answers? Try searching our database.

downloading file problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Dupont - 10 Apr 2006 02:52 GMT
In my application I download a file in the background.
With code like below:
====
Stream input;

new Thread(delegate(){
   int nRead, total = 0;
   byte[] buf = new byte[4096];
   using(FileStream output = new FileStream("output", FileMode.Create,
FileAccess.Write))
       while((nRead = input.Read(buf, 0, buf.Length) > 0)
           output.Write(buf, 0, nRead);
}).Start();
====
Where input is a network stream (http://something), comes from a
WebRequest.GetResponse().GetResponseStream().

Now some customer experience repeatedly problem wit that. But as I
experience none it's hard to debug.

One customer reported the following exception:
====
Exception : System.IO.IOException

Message?? : The process cannot access the file 'C:\Documents and
Settings\gavin\Local Settings\Application Data\NovaMind
Software\NovaMindEditor\3.0.7.0\NovaMindEditor-3_0_8-Setup.exe' because it
is being used by another process.

Source??? : mscorlib
Help ?????:
Stack??? :

?? at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
?? at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean
bFromProxy)
?? at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access)
====
But this is the only place in the program, called only once, so why could
that be?
Daniel O'Connell [C# MVP] - 10 Apr 2006 06:37 GMT
> In my application I download a file in the background.
> With code like below:
[quoted text clipped - 39 lines]
> But this is the only place in the program, called only once, so why could
> that be?

Most of hte time it would be because its run twice, I agree. Are you sure
there is no way it could be called twice by a user doing something wrong?
Thats what I'd look for first. Maybe even stick in a  check so that the app
can fail gracefully if someone initates the download twice before the
application stops running.
Lloyd Dupont - 10 Apr 2006 07:49 GMT
Yeah, it "could be" that it runs twice in some unlikely circumstances.
So I wrote some checking code (a bit convoluted :-/)
Anyway some other mysterious problem seemed to be worst, somehow related,
and unclearly defined...

Signature

Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>

>
>> In my application I download a file in the background.
[quoted text clipped - 46 lines]
> app can fail gracefully if someone initates the download twice before the
> application stops running.

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.