Thread.Suspend()

A

Alan T

As the Suspend method is deprecated, what method can I use?

What I want to do is when the user press the button "Cancel", it will prompt
the user to confirm it he want to stop the process, I need to suspend the
thread before the user choose "Yes" or "No".
If he choose "Yes", I will call
Thread.Abort()
If he choose "No", I will call
Thread.Resume().
 
G

Guest

Hi Alan,

Suspending and then Aborting a thread may cause data integrity problems if
your thread in middle of updating some business data. And anyway these two
methods are deprecated in .Net 2.0.

If your thread is doing some routine data related manipulations in a loop
(or some loop kind of thing), then implement a small class that wraps your
thread and provide "Pause", "Resume" and "Stop" methods on that class. Define
your thread handler method as a method inside the class and based on the
state of the class object ("Pause", "Resume" and "Stop") let the thread
handler method pause, resume and stop by itself.

This way you gurantee the data safety in your application and also provide a
decent way of pausing, resuming and stopping the work done by your thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top