How to pause and resume a thread?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • endazyar
    New Member
    • Mar 2010
    • 11

    #1

    How to pause and resume a thread?

    Hi all, I'm studying on a traffic simulation project right now. However i have problem with pausing the threads. Each car is considered as a thread in my app. When the simulation is running i want to pause it. Thread.suspend( ) method doesnt work, since i have to stop the thread from altering data. Let's say if there is a car on the road, and i click on pause button, the car should stay there.
    Any ideas ?

    Thanks in advance.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Thread.Suspend( ) is obsolete. They recomend using Monitor, Mutex, Event, or Semaphores for controlling Threads.

    I've never gotten real in-depth with that stuff, so I cannot give you better advice then to look up how to use some of those classes

    Comment

    • PsychoCoder
      Recognized Expert Contributor
      • Jul 2010
      • 465

      #3
      I would look into Thread.Sleep to stop the thread and Thread.Interrup t to restart it.

      Hope that helps :)

      NOTE: MSDN has a nice article on pausing & resuming threads.

      Comment

      Working...