RE: Thread class in Framework 2.0



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.
>
>
.



Relevant Pages

  • Re: suspend to ram, or hibernate [plus: monitor suspend howto]
    ... It does support suspend to disk only though, ... Anyway it's doc's says the 2.4.x kernels doesn't fully ... > thing I need is a way to manually send my monitor to suspend state. ...
    (Debian-User)
  • Re: FC2 and DPMS
    ... Dave Ulrick wrote: ... So on login screen my monitor goes in mode ... standby after 61 sec ... suspend after 63 sec ...
    (Fedora)
  • Re: [SLE] Suspend Monitor
    ... Sid Boyce wrote: ... Does this cause you monitor to go into standby or suspend mode? ... My understanding APM is for laptops and ACPI is for desktops. ...
    (SuSE)
  • Re: suspend to ram, or hibernate [plus: monitor suspend howto]
    ... "going to hibernate", and unloading everything, and stopping daemons, ... support suspend to ram, and suspend to disk. ... thing I need is a way to manually send my monitor to suspend state. ...
    (Debian-User)
  • [SLE] Suspend Monitor
    ... How do I get my Monitor to suspend? ... the monitor never went into standby let along suspend. ... This was under SuSE 8.2 ...
    (SuSE)