Filestream is not throwing exception when created for the same file - (async)

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi

I am downloading file from the server. The problem is described in
comments.Here is the code:

//input stream
using (Stream stream = res.GetResponseStream())
{

//Problem is here. When I'm trying to download the
same file while previous is still downloading
//the file stream doesn't throw any exception
saying that other process is actually using it
//it simply hangs on this line.
//when other process ends then i have to wait few
seconds to see messagebox with exception
//how to force it to throw exception immidiately
//background worker belongs to the DownloadForm
using (FileStream fs = new
System.IO.FileStream(path, System.IO.FileMode.OpenOrCreate)
{
int i = 0;
long total = 0;

byte[] buffer = new byte[32768];

while (((i = stream.Read(buffer, 0,
buffer.Length)) > 0) && !Stop)
{
fs.Write(buffer, 0, i);
total += i;
downloadWorker.ReportProgress((int)(total
* 100 / fileSize));
if (total >= fileSize) break;
}
}
}

Kind Regards
PK
.



Relevant Pages

  • SerialisationException: Request for the permission of type failed.
    ... I'm getting a serialisation exception with an inner permission error ... TSI.DRICE.Interfaces (available to both client and server). ... t for the permission of type TSI.DRICE.Interfaces.EngineTypes failed. ... (Stream serializationStream, HeaderHandler handler, Boolean fCheck, ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Net Meter [radio station bit rate] tutorial please? I want to nail this????????
    ... The following post was the first time I mentioned NetMeter: ... pretty confident that the actual bit rate of the stream is 128 kbps ... What on earth could you mean by "extensive error correction" if you ... I'm not downloading anything, and the amount downloaded is minimal. ...
    (alt.radio.digital)
  • Re: Timer Issue
    ... //create a stream reader grabbing text we get over HTTP ... while the file is downloading ... //when the working buffer size hits 0 then we know that the file has ... while (workingbuffersize> 0) ...
    (microsoft.public.dotnet.framework)
  • Re: Timer Issue
    ... //create a stream reader grabbing text we get over HTTP ... while the file is downloading ... //when the working buffer size hits 0 then we know that the file has ... while (workingbuffersize> 0) ...
    (microsoft.public.dotnet.framework)
  • Re: Hulu (was Re: Why Is Everything Worth Watching...)
    ... be downloaded, but the protocol used by RealPlayer, for example, ... to BBC radio (reading the RTSP stream to disk, converting to MP3, and ... downloading to a portable player for listening while walking, ...
    (rec.arts.sf.fandom)