Automatic updating.

  • Thread starter Thread starter Trygve Lorentzen
  • Start date Start date
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();

}
 
Trygve,

I'm not sure if you can wait, but have you checked out the ClickOnce
solution that is going to be delivered with .NET 2.0? It will address all
of the needs that you have, with minimal code.

Hope this helps.
 
Hi,

and thanks for your answer. Yes, I'm aware of the ClickOnce solution.
Actually we were hoping to use Zero Touch Deployment, but that didn't seem
mature enough at the time. No status indicator when downloading, slower
performance etc. Basically, we can't wait, but do you have any idea when
..NET 2.0 will be out? We have sceduled a beta release at the end of the
month...

If you have any suggestions to solve my download issues, I'd be greatful
too.

Cheers,
Trygve

Nicholas Paldino said:
Trygve,

I'm not sure if you can wait, but have you checked out the ClickOnce
solution that is going to be delivered with .NET 2.0? It will address all
of the needs that you have, with minimal code.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Trygve Lorentzen said:
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();

}
 
Back
Top