<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx</link><description>For time eternal there has been a way to suspend (and by association resume) another thread. It wasn&amp;#39;t until .NET 2.0 that someone took leadership and conceded that suspending another thread is not a safe thing to do. .NET 2.0 deprecates System.Threading</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1698982</link><pubDate>Thu, 09 Jul 2009 11:54:19 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1698982</guid><dc:creator>Gaurav</dc:creator><description>&lt;p&gt;Hi Peter ....&lt;/p&gt;
&lt;p&gt;Nice one!&lt;/p&gt;
&lt;p&gt;Your Implementaion is very good when we&amp;#39;ve multiple threads in our application ....I&amp;#39;ve some different situation but the same work....&lt;/p&gt;
&lt;p&gt;M creating &amp;nbsp;a window service Which take files from a specified folder ,Start a thread,This thread take files one by one, processes the file one by one &amp;nbsp;, then Delete the file.&lt;/p&gt;
&lt;p&gt;In between I want to Pause the window Service.To do this I want to suspend the thread..The problem is Susped is Obsolete.I can not use suspens &amp;amp; Resume......So how I can Implement Suspend &amp;amp; Resume by your Implementation...&lt;/p&gt;
&lt;p&gt;Thanks in advance&lt;/p&gt;
&lt;p&gt;-Gaurav&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1698982" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1686612</link><pubDate>Fri, 10 Apr 2009 12:59:35 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1686612</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;@James, you could simply add a read-only property to check the suspended field:&lt;/p&gt;
&lt;p&gt;public Boolean IsSuspended { get { return suspended; } }&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1686612" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1686545</link><pubDate>Fri, 10 Apr 2009 06:49:50 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1686545</guid><dc:creator>James Hall</dc:creator><description>&lt;p&gt;Hi Peter.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m new to threading and have not yet figured out how my threads can suspend themselves without using .Suspend()&lt;/p&gt;
&lt;p&gt;When using your code, how can another class poll MyThread to see if it is suspended?&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;James&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1686545" width="1" height="1"&gt;</description></item><item><title>I'm curious...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1684644</link><pubDate>Sat, 04 Apr 2009 13:52:38 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684644</guid><dc:creator>Bapproroumn</dc:creator><description>&lt;p&gt;Anyone know how old this forum is? As in what year it was started?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684644" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1668154</link><pubDate>Mon, 02 Feb 2009 14:08:18 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1668154</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;@Dave, yes, it would be better if SuspendableThread implemented IDisposable.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1668154" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1668023</link><pubDate>Mon, 02 Feb 2009 05:01:27 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1668023</guid><dc:creator>Dave Black</dc:creator><description>&lt;p&gt;Shouldn&amp;#39;t the SuspendableThread class implement IDisposable since it contains ManualResetEvent members which implement IDisposable (since they ultimately derive from WaitHandle and also explicitly implements IDisposable)?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1668023" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1667929</link><pubDate>Sun, 01 Feb 2009 21:57:55 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1667929</guid><dc:creator>John M.</dc:creator><description>&lt;p&gt;This worked! I used Async Sockets so they are non-Blocking and I was able to build the solution successful.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1667929" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1666695</link><pubDate>Wed, 28 Jan 2009 21:40:10 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1666695</guid><dc:creator>John M.</dc:creator><description>&lt;p&gt;Sorry again, I had forgotten about the class you created, suspendableThread. &amp;nbsp;The entire point of this blog...&lt;/p&gt;
&lt;p&gt;After reviewing this again, I think the only problem is if I place my blocking receive or send anywhere the thread is doing work, it will block the suspend request. &amp;nbsp;I will give this a try and also see if it works to change the socket connection to a non-blocking state with a while loop that keeps trying the receive unless a request to send comes up from the client.&lt;/p&gt;
&lt;p&gt;More to come!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1666695" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1666690</link><pubDate>Wed, 28 Jan 2009 21:25:11 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1666690</guid><dc:creator>John M.</dc:creator><description>&lt;p&gt;Sorry, I do not have a detailed answer to this yet, but the bad news is when you try to use the .Suspend after the thread variable name, Visual Studio 2005 with CE 5.0 selected as the deploy option does not include Suspend as a valid option.&lt;/p&gt;
&lt;p&gt;I can only select from these:&lt;/p&gt;
&lt;p&gt;Abort&lt;/p&gt;
&lt;p&gt;IsBackground&lt;/p&gt;
&lt;p&gt;Join&lt;/p&gt;
&lt;p&gt;ManagedThreadId&lt;/p&gt;
&lt;p&gt;Name&lt;/p&gt;
&lt;p&gt;Priority&lt;/p&gt;
&lt;p&gt;Start&lt;/p&gt;
&lt;p&gt;This is a tough one. &amp;nbsp;I was able to tune my code so that I am getting a 3 second response for either a local interactive user or from host/server side requests, however the constant disconnecting and connecting from the socket/server leaves me with a not so persistent socket connection.&lt;/p&gt;
&lt;p&gt;If you know anyone with Compact Frame Work, CE.Net, knowledge, please pass along this situation to them. &amp;nbsp;Thank you, Dave!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1666690" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1666666</link><pubDate>Wed, 28 Jan 2009 20:03:22 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1666666</guid><dc:creator>Dave Black</dc:creator><description>&lt;p&gt;Thanks for the article - I was looking for something like this.&lt;/p&gt;
&lt;p&gt;One question though - shouldn&amp;#39;t the SuspendableThread class implement IDisposable since it contains ManualResetEvent members which implement IDisposable (since they ultimately derive from WaitHandle and also explicitly implements IDisposable)?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1666666" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1666238</link><pubDate>Tue, 27 Jan 2009 05:10:42 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1666238</guid><dc:creator>John M.</dc:creator><description>&lt;p&gt;I have a problem with needing to suspend a thread that is running a blocking socket operation. &amp;nbsp;Once a receive has started, the operation blocks until it receives something. &amp;nbsp;I need to suspend this block, then allow a send thread to send on the same socket. &amp;nbsp;Once the send finishes or a period of time passes, I need to suspend the send thread that may also be blocking and allow the receive thread to run again. &amp;nbsp;Since I am working with c# and deploying to a device running CE 5.0, I have no timeout on the socket commands (the receivetimeout and sendtimeout are not supported in CE for some crazy reason), no way to notify the socket to stop blocking and if I disconnect the socket that stops the block, the server looses the unique handle of the socket it was conversing with, so server side sends fail regularly when a user trys to ramdomly send information to the connected &amp;nbsp;socket handle that is constantly being disconnected and reconnected. &amp;nbsp;Do you know of a solution for this problem?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1666238" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1662307</link><pubDate>Thu, 15 Jan 2009 21:05:23 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1662307</guid><dc:creator> Steve</dc:creator><description>&lt;p&gt;Good stuff...wish I&amp;#39;d seen this 6 months ago. Anyway..I have a VB6 app that uses a .NET DLL via COM (my DLL) to insert a bunch of transactions into a SQL database and inteface with another .NET app. &amp;nbsp;The COM DLL opens the connection, handles DB login, inserts transaction records, and handles all the SQL interaction, while the VB app sits and waits. The COM dll currently displays a wait form via another thread to show a animated GIF. &amp;nbsp;Here&amp;#39;s the code that controls the thread:&lt;/p&gt;
&lt;p&gt; &amp;lt;System.Runtime.InteropServices.ComVisible(False)&amp;gt; _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Public Sub ShowWaitForm(ByVal Show As Boolean)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Static thrd As System.Threading.Thread&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If Show Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;thrd = New System.Threading.Thread(AddressOf ShowForm)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;thrd.Start()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If thrd IsNot Nothing Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;thrd.Abort()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;thrd.Join()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;thrd = Nothing&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;End Sub&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;System.Runtime.InteropServices.ComVisible(False)&amp;gt; _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Private Sub ShowForm()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Try&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;frmWait = New WaitForm&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;frmWait.ShowDialog()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Catch ex As System.Threading.ThreadAbortException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.Threading.Thread.ResetAbort()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Finally&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If frmWait IsNot Nothing Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;frmWait.Hide()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;frmWait = Nothing&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;#39;Finally&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Try&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;End Sub&lt;/p&gt;
&lt;p&gt;This works for us pretty well, although every now and then, a ThreadAbort Exception is displayed. &amp;nbsp;What are we doing wrong to get this exception? &amp;nbsp;Is there a better way to terminate the thread than ThreadAbort? &amp;nbsp;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1662307" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1652654</link><pubDate>Fri, 31 Oct 2008 13:43:31 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1652654</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;@minhvc: Do you have a dual-core CPU and are you performing lots of work in with your Thread class? &amp;nbsp;That&amp;#39;s normal. &amp;nbsp;If you thread is using 100% of that CPU (or core) then it will be using 50% of all CPUs--which will show up as 50% in Task Manager.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1652654" width="1" height="1"&gt;</description></item><item><title>CPU resouse</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1652613</link><pubDate>Fri, 31 Oct 2008 07:31:21 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1652613</guid><dc:creator>minhvc</dc:creator><description>&lt;p&gt;When use the thread class for my application. It use 50% CPU resource. How to fix it?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1652613" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1652273</link><pubDate>Tue, 28 Oct 2008 16:21:27 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1652273</guid><dc:creator>Aaron</dc:creator><description>&lt;p&gt;Any chance you could explain why the while loop wrapping the Interlocked.Exchange calls in the Suspend and Resume methods is necessary?&lt;/p&gt;
&lt;p&gt;It almost seems to be saying &amp;quot;keep trying until we&amp;#39;re *sure* that the value was set&amp;quot;, but isn&amp;#39;t Interlocked.Exchange pretty much guaranteed to be successful in that respect? &amp;nbsp;What potential problems could occur with just a single (non-looped) Exchange?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1652273" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1647376</link><pubDate>Wed, 10 Sep 2008 17:47:03 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1647376</guid><dc:creator>Ali Zamurad</dc:creator><description>&lt;p&gt;First off - Great work Peter. I am wondering if you could suggest some in my situation. I have a GUI app which needs to be very responsive and it depends upon the data that come in files, so I created a background thread that runs infinitely and pooling files that got parse and displayed on the GUI. Since the GUI is dynamic and can change what file should be pooled now I want to suspend and resume that backgroud thread - this is where I think I could use your class. In the mean time I tried to use Thread.Abort but sometimes it does not finishes the thread. Also even I shutdown the main GUI the thread since dangles and appear in the Task Manager. The thread property Isbackground is set to true. What am I missing?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1647376" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1639251</link><pubDate>Thu, 03 Jul 2008 15:32:09 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1639251</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;@Vikram. &amp;nbsp;Unless the thread terminates itself between the first Join and the Set call, you&amp;#39;re guaranteed to halt for 2 seconds.&lt;/p&gt;
&lt;p&gt;If the thread goes into a waitsleepjoin after you call Set, there&amp;#39;s not much you can do without calling Interrupt. &amp;nbsp;The thread will still see the Set when it next waits for that event; setting it again won&amp;#39;t make a difference. &amp;nbsp;It will only make a difference if the event is an auto reset and something else is waiting on the event as well--which is not a good thing; the event should be only used for termination of the thread.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1639251" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1639217</link><pubDate>Thu, 03 Jul 2008 08:33:52 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1639217</guid><dc:creator>Vikram</dc:creator><description>&lt;p&gt;Thanks Peter,&lt;/p&gt;
&lt;p&gt;Yes, I want the workerthread to come to a known end.&lt;/p&gt;
&lt;p&gt;I wrote the waitHandler.Set within the loop to cater a scenario where the workerthread goes to &amp;quot;waitsleepjoin&amp;quot;, between the waithandler.Set and workerthread.Join() call or rather after the &amp;#39;set&amp;#39; and before &amp;#39;join&amp;#39;.&lt;/p&gt;
&lt;p&gt;And I used ANTS profiler to see if my threads actually terminates and ends. And am happy to see it does once the GC runs.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1639217" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1639124</link><pubDate>Wed, 02 Jul 2008 15:56:25 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1639124</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;Vikram, I&amp;#39;d likely have to see more code to judge what would be the most appropriate answer. &amp;nbsp;But, from your code you appear to be attempting to wait for the thread to exit (by calling Join) then signalling the thread to exit (via the call to Set) if the Join times out after 2 seconds. &amp;nbsp;Join is the only reliable way to be informed of a thread exiting (polling IsAlive is problematic and introduces latency). &amp;nbsp;I&amp;#39;m assuming the worker thread is either performing work or waiting on waitHandler. &amp;nbsp;I would call waitHandler.Set before calling Join; but I would only call it once--I see no reason to repeatedly call Set.&lt;/p&gt;
&lt;p&gt;You&amp;#39;ll only get the ThreadStateException if the worker thread hasn&amp;#39;t been started. &amp;nbsp;You&amp;#39;ll also get a ThreadInterruptedException if the thread is interrupted while Join is waiting for the thread to exit--which sometimes occurs upon application shutdown if at thread hasn&amp;#39;t exited.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1639124" width="1" height="1"&gt;</description></item><item><title>re: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated...</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.Thread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-deprecated_2E00__2E00__2E00_.aspx#1639069</link><pubDate>Wed, 02 Jul 2008 05:48:21 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1639069</guid><dc:creator>Vikram</dc:creator><description>&lt;p&gt;Peter,&lt;/p&gt;
&lt;p&gt;I have build up a windows server, which does some file processing using multiple threads. Now there is a situation, where in I need to call the Stop() &amp;amp; Start(), which doesnt effect the windows service as such, but internally its like restarting the service. During this process I need to terminate all the active threads. My code to terminate the thread in the Stop() is similar to this:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (Thread.CurrentThread.ManagedThreadId != workerThread.ManagedThreadId)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;try&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Signal the thread.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Try to join the main thread with a timeout of 2sec&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;while (!workerThread.Join(2000))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Awake any sleeping thread&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;waitHandler.Set();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;catch (ThreadStateException tex)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tex.Message;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;Now, how do i ensure the thread have terminated properly, so that I can recreate new set of threads in the Start() method. I think currently my threads have gone to the WaitSleepJoin state and will get awakned any time.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1639069" width="1" height="1"&gt;</description></item></channel></rss>