That's the problem... Thread.Sleep is for pause the current thread and my
need is to pause another thread, let say one running something outside my
development scope (classes on a library).
For .NET 1.1 there was Thread.Suspend and Thread.Resume. But these were
dangerous in some scenarios and were marked as obsolete and will be
deprecated in next versions of the framework as stated by documentation but
there is no alternative?
NSA
That's why I asked if you can pass stop flag to another thread. Then you can
Sleep on this flag.
If you can't change coding for threads to pause, can you just kill the
thread and restart it when required? Is there's some stop flag / event
available. If not, probably you need to re-consider how threads were
designed initially. In worst case you can put them into another process and
kill processes hoping that Windows will properly cleanup killed process.
However in this case you might need to deal with possible resource leaks.
Lacking other details (how you start threads, which parameters are
available, or if it's possible to pass some dummy job to do nothing to
emulate sleep) it's not easy to propose something more sensible.
> That's the problem... Thread.Sleep is for pause the current thread and my
> need is to pause another thread, let say one running something outside my
[quoted text clipped - 25 lines]
>>>
>>> Néstor Sánchez A.
Peter Ritchie [C# MVP] - 10 Jul 2007 19:20 GMT
Thread.Sleep is never the correct means to pause a thread. What does "pause"
mean? For x milliseconds? Thread.Sleep does not do that; it sleeps for a
minimum of x milliseconds it's almost impossible for your thread to Sleep for
the number of milliseconds passed to Thread.Sleep, and the granularity
depends on the version of Windows running (could range in granularity of
15-25 ms). Plus, you've guaranteed your thread to be busy for x
milliseconds, which means the rest of your application must wait for this
thread to finish sleeping before it exits (unless you don't mind aborting the
thread; which is a bad thing).
If by "pause" you mean "pause until I ask you to awake" (which is usually
want you want to do) then Thread.Sleep is total inappropriate.
See
http://msmvps.com/blogs/peterritchie/archive/2007/04/26/thread-sleep-is-a-sign-o
f-a-poorly-designed-program.aspx
for more detail on why Thread.Sleep is a sign of a poorly designed program.
And see
http://msmvps.com/blogs/peterritchie/archive/2006/10/13/_2700_System.Threading.T
hread.Suspend_280029002700_-is-obsolete_3A00_-_2700_Thread.Suspend-has-been-depr
ecated_2E002E002E00_.aspx
for one means of writing a thread that can be asked to pause, resume and
terminate.

Signature
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
> That's why I asked if you can pass stop flag to another thread. Then you can
> Sleep on this flag.
[quoted text clipped - 36 lines]
> >>> is for the current thread -not another as i need- then... how I can
> >>> pause it???
Néstor Sánchez A. - 13 Jul 2007 00:53 GMT
Thank you so much. I'll take the second link solution.
NSA
> Thread.Sleep is never the correct means to pause a thread. What does
> "pause"
[quoted text clipped - 67 lines]
>> >>> is for the current thread -not another as i need- then... how I can
>> >>> pause it???