Home All Groups Group Topic Archive Search About

downloading file problem

Author
10 Apr 2006 1:52 AM
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?

Author
10 Apr 2006 5:37 AM
Daniel O'Connell [C# MVP]
Show quote
"Lloyd Dupont" <net.galador@ld> wrote in message
news:%2320i6FEXGHA.2376@TK2MSFTNGP03.phx.gbl...
> 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.
Author
10 Apr 2006 6:49 AM
Lloyd Dupont
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>
Show quote
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:ui3%23pEGXGHA.3332@TK2MSFTNGP02.phx.gbl...
>
> "Lloyd Dupont" <net.galador@ld> wrote in message
> news:%2320i6FEXGHA.2376@TK2MSFTNGP03.phx.gbl...
>> 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.
>
>

AddThis Social Bookmark Button