.comment-link {margin-left:.6em;}


.. Hello Earthling .. \o/ :)

Dont Use Thread.Suspend() Method
Thursday, November 17, 2005

The Thread.Suspend documentation puts a nice easy to understand note:

"Do not use the Suspend and Resume methods to synchronize the activities of threads. You have no way of knowing what code a thread is executing when you suspend it. If you suspend a thread while it holds locks during a security permission evaluation, other threads in the AppDomain might be blocked. If you suspend a thread while it is executing a class constructor, other threads in the AppDomain that attempt to use that class are blocked. Deadlocks can occur very easily."

When you write "Thread.CurrentThread.Suspend( );" in the editor & build, you'll get the following warning:

'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. http://go.microsoft.com/fwlink/?linkid=14202'

do you know a way around this, or how to resolve this issue with the suspend and resume methods?
could you post some sample code or give me a site that will fix this error for me?
much appreciated
new guy
Hi, this *issue* cannot be fixed by just any of the available methods. Its a problem of thread synchronisation. The document, as I wrote, points out clearly that you should use the classes available in System.Threading such as Event etc. Now it can be confusing to understand incase you are new to thread synchronization. In that case you should look for articles on internet related to thread synchronisation in C#/vb.net. Regarding thread.suspend: its wrong, in the first place, to suspend your thread through a thread.suspend or a sleep statement just because you *expect* something to have happened by the time your wait time expires. For example:
while (true)
Sleep (1000); // or a suspend statement here
if (something_done)

I would say its a wrong design. Instead you should have some thread synchronisation object on which you could wait, and that wait should be released by the task on which you are waiting. I know how this kind of code is written in c++ but I dont clearly remember what classes to use in C# since i havnt worked on it for quite some time (but Event class is one). I dont promise to write a blog post on this but I can say I'll try. But dont count on it :)
In principle, a good happen, support the views of the author
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Online Training from India. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
JavaScript Online Training from India
Post a Comment

Links to this post:

Create a Link

<< Home


MSDN Blogs
Joel Pobar
Don Syme

Muhammad Ali
Lahore Food Blog

Tech Blog



June 2004   July 2004   August 2004   September 2004   October 2004   November 2004   December 2004   February 2005   April 2005   June 2005   July 2005   September 2005   October 2005   November 2005   June 2007   December 2007   January 2008   March 2008   April 2008   June 2008   October 2008   February 2009   May 2009   June 2009   July 2009   August 2009   March 2011   June 2011   July 2011   September 2011   October 2011   November 2011   December 2012   May 2013   October 2013   May 2014   March 2015   July 2015   August 2015   December 2015   March 2016   July 2016   October 2016   November 2016   July 2017   December 2017   May 2018  

This page is powered by Blogger. Isn't yours?