Thread.Suspend()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan T

    Thread.Suspend()

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


  • Adityanand Pasumarthi

    #2
    RE: Thread.Suspend( )

    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.

    --
    Regards,
    Aditya.P


    "Alan T" wrote:
    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() .
    >
    >
    >

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Thread.Suspend( )

      Alan T <alanpltseNOSPA M@yahoo.com.auw rote:
      As the Suspend method is deprecated, what method can I use?
      See http://www.pobox.com/~skeet/csharp/t...shutdown.shtml

      You can very easily apply the same technique to pausing a thread.

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      Working...