<?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>Mon, 23 Aug 2010 18:21:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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>
	<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-5468</link>
		<dc:creator>mech</dc:creator>
		<pubDate>Wed, 26 Aug 2009 12:31:14 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-5468</guid>
		<description>Hi Joe,
I already explained this in my email, but I&#039;ll repeat it here (maybe someone else will have similar problem):
 - the installer does not check if your application is running; however it can encounter locked files during install and complain about it
 - the installer offers repair/remove options if you run the msi for the same version that is already installed in the system</description>
		<content:encoded><![CDATA[<p>Hi Joe,<br />
I already explained this in my email, but I&#8217;ll repeat it here (maybe someone else will have similar problem):<br />
 &#8211; the installer does not check if your application is running; however it can encounter locked files during install and complain about it<br />
 &#8211; the installer offers repair/remove options if you run the msi for the same version that is already installed in the system</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe T.</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-5394</link>
		<dc:creator>Joe T.</dc:creator>
		<pubDate>Fri, 21 Aug 2009 22:56:01 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-5394</guid>
		<description>i&#039;m having only one (so far) problem with this:
The installer thread starts, but the existing application remains running until AFTER the setup.exe has initiated. As a result, the installer sees the existing application in-use and offers &quot;Repair / Remove&quot; options rather than the normal installation routine.

i would REEEEALLY appreciate help on this, as i&#039;d like to apply this method to all our in-house projects. Please let me know if i can send you a .cs file or something to see what i&#039;m doing.

Thanks VERY much for the tutorial!</description>
		<content:encoded><![CDATA[<p>i&#8217;m having only one (so far) problem with this:<br />
The installer thread starts, but the existing application remains running until AFTER the setup.exe has initiated. As a result, the installer sees the existing application in-use and offers &#8220;Repair / Remove&#8221; options rather than the normal installation routine.</p>
<p>i would REEEEALLY appreciate help on this, as i&#8217;d like to apply this method to all our in-house projects. Please let me know if i can send you a .cs file or something to see what i&#8217;m doing.</p>
<p>Thanks VERY much for the tutorial!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: faiz</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-5265</link>
		<dc:creator>faiz</dc:creator>
		<pubDate>Fri, 14 Aug 2009 05:14:52 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-5265</guid>
		<description>thanks a lot mate.</description>
		<content:encoded><![CDATA[<p>thanks a lot mate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jake</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-4066</link>
		<dc:creator>Jake</dc:creator>
		<pubDate>Fri, 26 Jun 2009 11:44:12 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-4066</guid>
		<description>Coherent and structured tutorial with first rate examples. Thanks a million!</description>
		<content:encoded><![CDATA[<p>Coherent and structured tutorial with first rate examples. Thanks a million!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</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-3329</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Thu, 28 May 2009 14:49:33 +0000</pubDate>
		<guid isPermaLink="false">http://themech.net/?p=110#comment-3329</guid>
		<description>Nice post, thanks very much.  I will definitely try this out to see how it works for me.</description>
		<content:encoded><![CDATA[<p>Nice post, thanks very much.  I will definitely try this out to see how it works for me.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
