RE: Thread class in Framework 2.0
- From: "Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 14 Jul 2005 07:16:05 -0700
I have not researched the solution, so I can only offer guidance in general.
This should give some background for the reasoning:
http://blogs.msdn.com/oldnewthing/archive/2003/12/09/55988.aspx
Microsoft's suggestion is to use another class, like a Monitor, Mutex, etc.
to fulfill your need. The reasoning is simple. Suspend can leave an object in
a state where it is blocked, causing deadlocks for other processes attempting
to gain access.
Take the Monitor, for example. It is better to have the monitor kick the
thread off the object and free it up for other work than it is to have the
work simply suspended. The downside, of course, is you must reconnect the
thread to the object to begin work again.
If you are sure that nothing else can use the object other than the thread
in question, you can continue to use the deprecated methods, but realize that
you are inviting potential issues in the future.
If it is your own object that might be blocked, you can make it "thread
safe" by making a struct out of it, forcing it on the heap. Note, however,
that this means you will end up with the "object" in many memory spaces. You
can then suspend without worrying about deadlocks. This does not solve the
deprecated issue, but it certainly makes working with deprecated methods
safer. NOTE, however, that you can go overboard with structs, causing a stack
overflow (if you make all "objects" into structure, for example).
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Dodo Cibelli" wrote:
>
> In the .NET Framwrok 2.0 the methods
>
> Suspend();
> Resume();
>
> of the Thread Class are marked as Obsolete
>
> [ObsoleteAttribute("Thread.Resume 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", false)]
> public void Resume();
>
> How if I have a backgroud thread ( say a very long and time consuming
> simulation ) and I want to easily give the use the ability to suspend it to
> use his pc for a while without that load ?
> And then resume it ?
> I do beleve that this is not the the right way to sincornize Threads but
> what if you want just to suspend a thread.
>
>
.
- References:
- Thread class in Framework 2.0
- From: Dodo Cibelli
- Thread class in Framework 2.0
- Prev by Date: Adding domain user account to local administrator group
- Next by Date: RE: how to change the value of Request.ServerVariables["HTTP_REFERER"]
- Previous by thread: Thread class in Framework 2.0
- Next by thread: Re: Thread class in Framework 2.0
- Index(es):
Relevant Pages
|