T
Trygve Lorentzen
Hi,
I'm developing an app with automatic version checking and updating. It must
also track what version is installed for each customer in our customer
database. I have made a small client to fetch updated file(s) from the net
and copy over the old files. I figured this must be done since the program
itself will be read/write locked as long as it is running. I have a
progressbar prgDownload that shows the download progress. My main problem
right now is that the download is extremely slow the way I have programmed
it to make it work with the progress bar.
I have also looked into the Application Updater Block
(http://dotnetjunkies.com/WebLog/bsblog/archive/2004/06/10/16118.aspx), but
I don't think this is applicable to my solution since I need to keep track
of installed versions and I also need some custom checking on when updates
are needed.
Anyone have any suggestions to how I can speed up the download? Or perhaps
totally different approaches to what I'm trying to accomplish? Any help will
be greatly appreciated. The speed problem is probably because I read and
write one byte at a time, guess I need to use BufferedReader or something
similar, but I need some code examples to make it work.
Old code without progressbar (fast download):
// // Create a web client.
// WebClient wc = new WebClient();
//
// // The file name.
// string fileName = Application.StartupPath + Path.DirectorySeparatorChar +
"Transport.tmp";
//
// // Delete the old file if it exists.
// File.Delete(fileName);
//
// // Download the file.
// wc.DownloadFile("http://proteria.com/files/Transport.exe",
Application.StartupPath
// + Path.DirectorySeparatorChar + "Transport.tmp");
New code that works with progress bar but is VERY SLOW:
Uri downloadLoc = new Uri("http://proteria.com/files/Transport.exe");
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(downloadLoc);
WebResponse rsp = req.GetResponse();
Stream inStream = rsp.GetResponseStream();
// BufferedStream bs = new BufferedStream(inStream);
File.Delete(Application.StartupPath + Path.DirectorySeparatorChar +
"Transport.tmp");
FileStream fs = File.Create(Application.StartupPath +
Path.DirectorySeparatorChar + "Transport.tmp");
prgDownload.Properties.Step = 1;
prgDownload.Properties.PercentView = true;
prgDownload.Properties.Maximum = (int)(rsp.ContentLength/4096);
prgDownload.Properties.Minimum = 0;
int i = 0;
while(true)
{
int i = inStream.Read();
if(i == -1)
break;
fs.WriteByte((byte)i);
prgDownload.Increment(70);
prgDownload.Update();
}
I'm developing an app with automatic version checking and updating. It must
also track what version is installed for each customer in our customer
database. I have made a small client to fetch updated file(s) from the net
and copy over the old files. I figured this must be done since the program
itself will be read/write locked as long as it is running. I have a
progressbar prgDownload that shows the download progress. My main problem
right now is that the download is extremely slow the way I have programmed
it to make it work with the progress bar.
I have also looked into the Application Updater Block
(http://dotnetjunkies.com/WebLog/bsblog/archive/2004/06/10/16118.aspx), but
I don't think this is applicable to my solution since I need to keep track
of installed versions and I also need some custom checking on when updates
are needed.
Anyone have any suggestions to how I can speed up the download? Or perhaps
totally different approaches to what I'm trying to accomplish? Any help will
be greatly appreciated. The speed problem is probably because I read and
write one byte at a time, guess I need to use BufferedReader or something
similar, but I need some code examples to make it work.
Old code without progressbar (fast download):
// // Create a web client.
// WebClient wc = new WebClient();
//
// // The file name.
// string fileName = Application.StartupPath + Path.DirectorySeparatorChar +
"Transport.tmp";
//
// // Delete the old file if it exists.
// File.Delete(fileName);
//
// // Download the file.
// wc.DownloadFile("http://proteria.com/files/Transport.exe",
Application.StartupPath
// + Path.DirectorySeparatorChar + "Transport.tmp");
New code that works with progress bar but is VERY SLOW:
Uri downloadLoc = new Uri("http://proteria.com/files/Transport.exe");
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(downloadLoc);
WebResponse rsp = req.GetResponse();
Stream inStream = rsp.GetResponseStream();
// BufferedStream bs = new BufferedStream(inStream);
File.Delete(Application.StartupPath + Path.DirectorySeparatorChar +
"Transport.tmp");
FileStream fs = File.Create(Application.StartupPath +
Path.DirectorySeparatorChar + "Transport.tmp");
prgDownload.Properties.Step = 1;
prgDownload.Properties.PercentView = true;
prgDownload.Properties.Maximum = (int)(rsp.ContentLength/4096);
prgDownload.Properties.Minimum = 0;
int i = 0;
while(true)
{
int i = inStream.Read();
if(i == -1)
break;
fs.WriteByte((byte)i);
prgDownload.Increment(70);
prgDownload.Update();
}