<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Check for updates: how to download and install a new version of your C# application</title>
	<atom:link href="http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/feed/" rel="self" type="application/rss+xml" />
	<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/</link>
	<description>Python, software development, stock exchange, C#</description>
	<lastBuildDate>Fri, 20 Jan 2012 10:33:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: mech</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-48767</link>
		<dc:creator>mech</dc:creator>
		<pubDate>Fri, 18 Nov 2011 10:12:40 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-48767</guid>
		<description>RvdH: You create the WebRequest and get the response. The response headers should contain the &quot;content-length&quot;, which is the total installer size. Now, in the loop you read the installer from the reponse stream and update the progress bar based on total length and the downloaded bytes counter. You just should be careful about the threads: if you create the progress bar in the main UI thread and download the installer in the background, the progress bar should be updated by the main thread (f.e. the backgound thread calls the main thread delegate using BeginInvoke in order to update the progress bar).</description>
		<content:encoded><![CDATA[<p>RvdH: You create the WebRequest and get the response. The response headers should contain the &#8220;content-length&#8221;, which is the total installer size. Now, in the loop you read the installer from the reponse stream and update the progress bar based on total length and the downloaded bytes counter. You just should be careful about the threads: if you create the progress bar in the main UI thread and download the installer in the background, the progress bar should be updated by the main thread (f.e. the backgound thread calls the main thread delegate using BeginInvoke in order to update the progress bar).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manu30</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-45410</link>
		<dc:creator>Manu30</dc:creator>
		<pubDate>Sun, 30 Oct 2011 16:24:47 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-45410</guid>
		<description>Thanks a lot for this nice programm.
I&#039;ve certainly saved a few days</description>
		<content:encoded><![CDATA[<p>Thanks a lot for this nice programm.<br />
I&#8217;ve certainly saved a few days</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RvdH</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-42024</link>
		<dc:creator>RvdH</dc:creator>
		<pubDate>Wed, 28 Sep 2011 15:46:35 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-42024</guid>
		<description>Anyone knows a way for displaying a progress indicator while downloading the update?</description>
		<content:encoded><![CDATA[<p>Anyone knows a way for displaying a progress indicator while downloading the update?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mech</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-13160</link>
		<dc:creator>mech</dc:creator>
		<pubDate>Thu, 28 Oct 2010 11:58:54 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-13160</guid>
		<description>espinete,
I&#039;ve just created a simple example project, you can download it here: http://themech.net/downloads/CheckForUpdateExample.zip . It will check for the new version and ask the user if he want to download it. This is just a quick example, so it will download the Eyes Relax installer.</description>
		<content:encoded><![CDATA[<p>espinete,<br />
I&#8217;ve just created a simple example project, you can download it here: <a href="http://themech.net/downloads/CheckForUpdateExample.zip" rel="nofollow">http://themech.net/downloads/CheckForUpdateExample.zip</a> . It will check for the new version and ask the user if he want to download it. This is just a quick example, so it will download the Eyes Relax installer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: espinete</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-12479</link>
		<dc:creator>espinete</dc:creator>
		<pubDate>Fri, 15 Oct 2010 18:33:28 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-12479</guid>
		<description>CAn you put all together in solution with all code and Sample Windows Forms Application for test Updater ?? thx</description>
		<content:encoded><![CDATA[<p>CAn you put all together in solution with all code and Sample Windows Forms Application for test Updater ?? thx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mech</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-9255</link>
		<dc:creator>mech</dc:creator>
		<pubDate>Tue, 06 Jul 2010 19:43:46 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-9255</guid>
		<description>Hello TheKidd,
I&#039;ll try to keep my explanation simple:
1) the main app thread (the UI thread) lanches the worker thread that will look for the new version and download it
2) For various reasons (the user pressed the cancel button on our check for updates dialog or closed our app) the main thread wants to finish the worker thread; to do so, it should call the StopThread (refer to the source in this tutorial). The StopThread method sets the stopping event and waits for the thread to stop
3) Now the worker thread won&#039;t stop until it finishes its work. But we cannot wait until it finishes the whole operation if we want to cancel it. So the worker thread should call the ShoudStop method (and it should do it quite often). If this method returns true, the worker thread simply finishes its work:
if (ShouldStop()) return; // that&#039;s all
Of course you should do the cleanup if the thread created some temporary files or has some open files/connections. You can do it before the return statement or in thread&#039;s &#039;finally&#039; section.
When I wrote in my comment about calling the ShouldStop method every 8K, I meant something like this (metacode):
while (!download_finished)
{
    if (ShouldStop())
    {
       //cleanup
       return;
    }
    result += read_8192_bytes_from_stream
}

If you have any further questions - please contact me.

Greetings,
mech</description>
		<content:encoded><![CDATA[<p>Hello TheKidd,<br />
I&#8217;ll try to keep my explanation simple:<br />
1) the main app thread (the UI thread) lanches the worker thread that will look for the new version and download it<br />
2) For various reasons (the user pressed the cancel button on our check for updates dialog or closed our app) the main thread wants to finish the worker thread; to do so, it should call the StopThread (refer to the source in this tutorial). The StopThread method sets the stopping event and waits for the thread to stop<br />
3) Now the worker thread won&#8217;t stop until it finishes its work. But we cannot wait until it finishes the whole operation if we want to cancel it. So the worker thread should call the ShoudStop method (and it should do it quite often). If this method returns true, the worker thread simply finishes its work:<br />
if (ShouldStop()) return; // that&#8217;s all<br />
Of course you should do the cleanup if the thread created some temporary files or has some open files/connections. You can do it before the return statement or in thread&#8217;s &#8216;finally&#8217; section.<br />
When I wrote in my comment about calling the ShouldStop method every 8K, I meant something like this (metacode):<br />
while (!download_finished)<br />
{<br />
    if (ShouldStop())<br />
    {<br />
       //cleanup<br />
       return;<br />
    }<br />
    result += read_8192_bytes_from_stream<br />
}</p>
<p>If you have any further questions &#8211; please contact me.</p>
<p>Greetings,<br />
mech</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TheKidd</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-9111</link>
		<dc:creator>TheKidd</dc:creator>
		<pubDate>Sun, 27 Jun 2010 10:09:20 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-9111</guid>
		<description>Hello Mech, thank you for such a great tutorial. I am new to threading in .Net so I am struggling with one part of your example.

In the CheckForNewVersion() and DownloadInstaller() functions, you have the following comment: use this.ShouldStop while checking so the thread can be interrupted: if this.ShouldStop() throw new ThreadInterruptedException(&quot;&quot;);

I understand what this is suppose to do, however, I am not sure how to properly implement this. Would I just add this to the top of my checkforversion/download code in each function or is there another way to properly implement this?

I saw your comment on Feb 22nd about calling this every 8K during download. Was unsure how to do this properly.

Thanks in advance for your help.</description>
		<content:encoded><![CDATA[<p>Hello Mech, thank you for such a great tutorial. I am new to threading in .Net so I am struggling with one part of your example.</p>
<p>In the CheckForNewVersion() and DownloadInstaller() functions, you have the following comment: use this.ShouldStop while checking so the thread can be interrupted: if this.ShouldStop() throw new ThreadInterruptedException(&#8220;&#8221;);</p>
<p>I understand what this is suppose to do, however, I am not sure how to properly implement this. Would I just add this to the top of my checkforversion/download code in each function or is there another way to properly implement this?</p>
<p>I saw your comment on Feb 22nd about calling this every 8K during download. Was unsure how to do this properly.</p>
<p>Thanks in advance for your help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ludovic</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-8200</link>
		<dc:creator>ludovic</dc:creator>
		<pubDate>Sun, 18 Apr 2010 07:01:20 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-8200</guid>
		<description>Thanks a lot, it was usefull.</description>
		<content:encoded><![CDATA[<p>Thanks a lot, it was usefull.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mech</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-7409</link>
		<dc:creator>mech</dc:creator>
		<pubDate>Mon, 22 Feb 2010 20:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-7409</guid>
		<description>Peter,
Well, my fault. Although there is &quot;how to download&quot; in the title of this blog entry, I&#039;ve decided to skip this step to keep the tutorial simple :) Downloading is pretty straightforward:

1) create the WebRequest with the installer address
2) use its request.GetResponse method to get the response (it will throw an Exception in case of HTTP error)
3) check the response.Headers to get the content-length
4) create the temporary file
5) read the response stream and save the installer to the temporary file (you can call ShouldStop method every 8K to check if the user canceled the action)
6) in case of any errors - remove the temporary file

If everything went OK, we launch the installer

Greetings,
mech</description>
		<content:encoded><![CDATA[<p>Peter,<br />
Well, my fault. Although there is &#8220;how to download&#8221; in the title of this blog entry, I&#8217;ve decided to skip this step to keep the tutorial simple :) Downloading is pretty straightforward:</p>
<p>1) create the WebRequest with the installer address<br />
2) use its request.GetResponse method to get the response (it will throw an Exception in case of HTTP error)<br />
3) check the response.Headers to get the content-length<br />
4) create the temporary file<br />
5) read the response stream and save the installer to the temporary file (you can call ShouldStop method every 8K to check if the user canceled the action)<br />
6) in case of any errors &#8211; remove the temporary file</p>
<p>If everything went OK, we launch the installer</p>
<p>Greetings,<br />
mech</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://themech.net/2008/09/check-for-updates-how-to-download-and-install-a-new-version-of-your-csharp-application/comment-page-1/#comment-7303</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Wed, 17 Feb 2010 05:24:48 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-7303</guid>
		<description>Thanks, this helps a lot!

BTW, where is the WebRequest code to download the msi file? Or am I missing something???

Thanks,
Peter</description>
		<content:encoded><![CDATA[<p>Thanks, this helps a lot!</p>
<p>BTW, where is the WebRequest code to download the msi file? Or am I missing something???</p>
<p>Thanks,<br />
Peter</p>
]]></content:encoded>
	</item>
</channel>
</rss>

