downloading file problem

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

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?
 
Lloyd Dupont said:
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?

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.
 
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...

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
Daniel O'Connell said:
Lloyd Dupont said:
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?

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.
 
Back
Top