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/bsbl...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.Sta rtupPath + Path.DirectoryS eparatorChar +
"Transport.tmp" ;
//
// // Delete the old file if it exists.
// File.Delete(fil eName);
//
// // Download the file.
// wc.DownloadFile ("http://proteria.com/files/Transport.exe",
Application.Sta rtupPath
// + Path.DirectoryS eparatorChar + "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.Crea te(downloadLoc) ;
WebResponse rsp = req.GetResponse ();
Stream inStream = rsp.GetResponse Stream();
// BufferedStream bs = new BufferedStream( inStream);
File.Delete(App lication.Startu pPath + Path.DirectoryS eparatorChar +
"Transport.tmp" );
FileStream fs = File.Create(App lication.Startu pPath +
Path.DirectoryS eparatorChar + "Transport.tmp" );
prgDownload.Pro perties.Step = 1;
prgDownload.Pro perties.Percent View = true;
prgDownload.Pro perties.Maximum = (int)(rsp.Conte ntLength/4096);
prgDownload.Pro perties.Minimum = 0;
int i = 0;
while(true)
{
int i = inStream.Read() ;
if(i == -1)
break;
fs.WriteByte((b yte)i);
prgDownload.Inc rement(70);
prgDownload.Upd ate();
}