Re: c# Thread problem

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Jul 4, 10:27 am, cty0...@xxxxxxxxx wrote:
I have some question..
This is my first time to use thread..
Following code does not have error but two warring

The warring is

Warning 2 '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'

The warring are happened thread Resume/Suspend..
I'm not sure what is problem becuase thread programing is first time
for me...

As it says, you shouldn't use Suspend/Resume, basically. If you need a
producer/consumer queue (which it looks like this is) you can use Auto/
ManualResetEvent, or Monitor.Wait/Pulse/PulseAll. See the second half
of
http://pobox.com/~skeet/csharp/threads/deadlocks.shtml for an example.

You also shouldn't manually be calling Monitor.Enter/Exit - use lock
instead.

Finally, making a UI thread block at all is a bad idea - you won't be
able to do things like move the window while it's blocked. Instead,
you should either work asynchronously or have another thread waiting
for messages and calling Control.BeginInvoke or Control.Invoke to use
that message on the UI thread.

Jon

.