471,330 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

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

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
Jun 27 '08 #1
0 751

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by GDL | last post: by
40 posts views Thread by Kevin Yu | last post: by
11 posts views Thread by Dorsa | last post: by
9 posts views Thread by ljlevend | last post: by
7 posts views Thread by Nathan Sokalski | last post: by
2 posts views Thread by ewingate | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.