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. replacement for Thread.Suspend(), Thread.Resume() ?

replacement for Thread.Suspend(), Thread.Resume() ?

Scheduled Pinned Locked Moved C#
csharpcomquestioncareerworkspace
4 Posts 2 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.
  • M Offline
    M Offline
    michal kreslik
    wrote on last edited by
    #1

    Hello, I am getting a C# compiler warning for using Thread.Suspend() and Thread.Resume() methods:

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

    I'm implementing these thread methods in a safe environment, when only a single worker thread accesses the resources. This worker thread is performing a lenghty calculation so I wanted to have an option to suspend/resume this CPU intensive and lenghty calculation. Is there any other simple way to accomplish this task? Monitor, Mutex, Event nor Semaphore don't seem to be an effective replacement for Suspend() and Resume(). Thanks much, Michal Kreslik

    R 1 Reply Last reply
    0
    • M michal kreslik

      Hello, I am getting a C# compiler warning for using Thread.Suspend() and Thread.Resume() methods:

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

      I'm implementing these thread methods in a safe environment, when only a single worker thread accesses the resources. This worker thread is performing a lenghty calculation so I wanted to have an option to suspend/resume this CPU intensive and lenghty calculation. Is there any other simple way to accomplish this task? Monitor, Mutex, Event nor Semaphore don't seem to be an effective replacement for Suspend() and Resume(). Thanks much, Michal Kreslik

      R Offline
      R Offline
      Russell Jones
      wrote on last edited by
      #2

      Thread.Sleep(Timeout.Infinite) should halt the thread. you can then interrupt it if you want it to start doing things again. HTH Russ

      M 1 Reply Last reply
      0
      • R Russell Jones

        Thread.Sleep(Timeout.Infinite) should halt the thread. you can then interrupt it if you want it to start doing things again. HTH Russ

        M Offline
        M Offline
        michal kreslik
        wrote on last edited by
        #3

        OK, thanks, but Sleep() is a static method, so it's not possible to call this method on any thread other than the current one, correct? That means that it's not possible to put a thread to sleep externally this way. Is that true or am I missing something? Thank you, Michal Kreslik

        R 1 Reply Last reply
        0
        • M michal kreslik

          OK, thanks, but Sleep() is a static method, so it's not possible to call this method on any thread other than the current one, correct? That means that it's not possible to put a thread to sleep externally this way. Is that true or am I missing something? Thank you, Michal Kreslik

          R Offline
          R Offline
          Russell Jones
          wrote on last edited by
          #4

          i think the aim of the changes to the resume and suspend methods was that code that executes outside a thread doesn't know what resources the thread is using. If for instance there was a database transaction open in the thread that you are putting to sleep you could create chaos for all users of the application not just the specific instance that the thread is running in. I think the general plan is to check for the state of a variable somewhere in your code while(_running) {DoStuff();} else { ReleaseExpensiveResources(); Thread.Sleep(Timeout.Infinite); } This way the thread won't suspend immedeately but it will suspend cleanly when it releases. Russ

          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