Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Sleep thread

Sleep thread

Scheduled Pinned Locked Moved C#
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yesu prakash
    wrote on last edited by
    #1

    Hi, How can i sleep a thread for ever and how to continue the thread which is sleeping for ever? I need to use in pause and play. Thankyou YPKI

    R 1 Reply Last reply
    0
    • Y yesu prakash

      Hi, How can i sleep a thread for ever and how to continue the thread which is sleeping for ever? I need to use in pause and play. Thankyou YPKI

      R Offline
      R Offline
      Ravadre
      wrote on last edited by
      #2

      Infinite wait is not the best option in most cases, timeout can be handy. And for your problem, you could use ManualResetEvent. Msdn[^]

      _ 1 Reply Last reply
      0
      • R Ravadre

        Infinite wait is not the best option in most cases, timeout can be handy. And for your problem, you could use ManualResetEvent. Msdn[^]

        _ Offline
        _ Offline
        _groo_
        wrote on last edited by
        #3

        I agree, ManualResetEvent is IMHO the best solution. In your case you might not need a timeout, however, because a long pause does not indicate an exceptional case (if you are making a "play/pause" sort of functionality). But remember to implement IDisposable in your class, and signal the ManualResetEvent before Disposing to make sure that your background thread ends also, otherwise you will end up waiting forever.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups