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. Visual Basic
  4. Question about Threading

Question about Threading

Scheduled Pinned Locked Moved Visual Basic
questioncareer
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.
  • P Offline
    P Offline
    Psycho Coder Extreme
    wrote on last edited by
    #1

    In my application I have a process that can take quite a bit of time to run (so I have it in it's own thread so I can display progress to the user). In the event that a 2nd process starts I need to pause the thread, then restart it once the 2nd process is complete. When I use Thread.Resume to restatt it it displays a warning

    Public Sub Resume()' is obsolete: 'Thread.Resume has been deprecated.
    Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.

    What are the acceptable replacements for .Resume as I have Google'd it and cant find the answer

    "It's only that urgent if you have to pee." Dave Kreskowiak

    D 1 Reply Last reply
    0
    • P Psycho Coder Extreme

      In my application I have a process that can take quite a bit of time to run (so I have it in it's own thread so I can display progress to the user). In the event that a 2nd process starts I need to pause the thread, then restart it once the 2nd process is complete. When I use Thread.Resume to restatt it it displays a warning

      Public Sub Resume()' is obsolete: 'Thread.Resume has been deprecated.
      Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.

      What are the acceptable replacements for .Resume as I have Google'd it and cant find the answer

      "It's only that urgent if you have to pee." Dave Kreskowiak

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Psycho-*Coder*-Extreme wrote:

      I need to pause the thread, then restart it once the 2nd process is complete

      How did you "pause" this thread?? I hope you didn't call Abort() on it. Once a thread is stopped, that's it, you can't restart it. You have to destroy it and create another one. Your thread should be checking for a flag set by your main thread to tell it to "pause". Once the 2nd process completes, you can reset this flag telling your first thread to resume.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      P 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Psycho-*Coder*-Extreme wrote:

        I need to pause the thread, then restart it once the 2nd process is complete

        How did you "pause" this thread?? I hope you didn't call Abort() on it. Once a thread is stopped, that's it, you can't restart it. You have to destroy it and create another one. Your thread should be checking for a flag set by your main thread to tell it to "pause". Once the 2nd process completes, you can reset this flag telling your first thread to resume.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        P Offline
        P Offline
        Psycho Coder Extreme
        wrote on last edited by
        #3

        For pausing it I use

        'Put the thread to sleep for as long as I need it
        Thread.Sleep(System.Threading.Timeout.Infinite)
        'Set the flag
        bIsPaused = True

        Then to resume it I use

        'Check the status of the thread
        If thrdAgentStatus.ThreadState And ThreadState.Unstarted <> 0 And Not bIsPaused Then
        thrdAgentStatus.Start()
        Else
        thrdAgentStatus.Resume()
        End If

        My problem is that the .Resume gives a warning that it is depreciated and I was trying to find an alternative so I can get rid of this warning.

        "Okay, I give up: which is NOT a real programming language????" Michael Bergman

        D 1 Reply Last reply
        0
        • P Psycho Coder Extreme

          For pausing it I use

          'Put the thread to sleep for as long as I need it
          Thread.Sleep(System.Threading.Timeout.Infinite)
          'Set the flag
          bIsPaused = True

          Then to resume it I use

          'Check the status of the thread
          If thrdAgentStatus.ThreadState And ThreadState.Unstarted <> 0 And Not bIsPaused Then
          thrdAgentStatus.Start()
          Else
          thrdAgentStatus.Resume()
          End If

          My problem is that the .Resume gives a warning that it is depreciated and I was trying to find an alternative so I can get rid of this warning.

          "Okay, I give up: which is NOT a real programming language????" Michael Bergman

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Psycho-*Coder*-Extreme wrote:

          'Put the thread to sleep for as long as I need itThread.Sleep(System.Threading.Timeout.Infinite)'Set the flagbIsPaused = True

          OK. That's not going to work. The flag is never set because the thread sleeps, or Blocks, immediately. Start and Resume will not "wake up" a blocked thread. You have to call the Thread object's Interrupt method to unblock a blocked thread.

          Dim oThread As System.Threading.Thread
          oThread = New Thread(AddressOf Me.Fill)
          oThread.Start()
          oThread.Sleep(System.Threading.Timeout.Infinite)
          
          Dim retValue As MsgBoxResult = MsgBox("Wake Thread?")
          If retValue = MsgBoxResult.Yes Then
              oThread.Interrupt()
          End If
          

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          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