Pause not Sleep

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cintury
    New Member
    • May 2007
    • 81

    Pause not Sleep

    Hi All,

    I'm developing a mobile app in VB and I was wondering if there was anyway to pause or wait a thread without putting it to sleep. I'm just trying to maintain a wireless network connection while I check internet connectivity for 30 secs but if I put the thread to sleep the connection itself closes. The current method is
    Code:
    _sleepTimeBetweenConnectTries = 900 'milliseconds 
    System.Threading.Thread.Sleep(_sleepTimeBetweenConnectTries)
    I'm racking my brain and the sdk to see if there is a wait or pause or delay function but all I can find is sleep and that is not what I want.
    Thanks
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by Cintury
    Hi All,

    I'm developing a mobile app in VB and I was wondering if there was anyway to pause or wait a thread without putting it to sleep. I'm just trying to maintain a wireless network connection while I check internet connectivity for 30 secs but if I put the thread to sleep the connection itself closes. The current method is
    Code:
    _sleepTimeBetweenConnectTries = 900 'milliseconds 
    System.Threading.Thread.Sleep(_sleepTimeBetweenConnectTries)
    I'm racking my brain and the sdk to see if there is a wait or pause or delay function but all I can find is sleep and that is not what I want.
    Thanks
    this sub might be of help:

    [CODE=vb]sub mySleep (Secs as single)
    dim t as single
    t=timer
    do
    doevents
    loop until (secs+t) <= timer
    end sub[/CODE]

    ^.^

    Comment

    • Cintury
      New Member
      • May 2007
      • 81

      #3
      Originally posted by kadghar
      this sub might be of help:

      [CODE=vb]sub mySleep (Secs as single)
      dim t as single
      t=timer
      do
      doevents
      loop until (secs+t) <= timer
      end sub[/CODE]

      ^.^
      Thanks for the help I think your idea just might work but just a few errors. when I try to use timer I get this error:

      'Timer' is ambiguous, imported from the namespaces or types 'System.Threadi ng, System.Windows. Forms'.

      Comment

      • kadghar
        Recognized Expert Top Contributor
        • Apr 2007
        • 1302

        #4
        Originally posted by Cintury
        Thanks for the help I think your idea just might work but just a few errors. when I try to use timer I get this error:

        'Timer' is ambiguous, imported from the namespaces or types 'System.Threadi ng, System.Windows. Forms'.
        Thats a problem, i suppose because of the Mobile system.

        Timer will get the seconds that have passed this day, but any other function that calls the system time will do. I think you'll have to find out which one fits better here. (maybe 'NOW')

        Comment

        • Cintury
          New Member
          • May 2007
          • 81

          #5
          Ok I've got the timer setup and I believe its running. I just need to create a busy (do nothing loop) until the timer hits its designated interval. This is what I have so far. I'm looking to exit the timer once the interval is up and return to the calling method. I just don't know how to compare the time object in the timer. I'm trying to setup a Do Nothing While timer.currentti me < timer.interval loop.

          Code:
          Private Sub StarthttpTimer(ByVal waitTime As Integer)
          
          
                  httpTimer = New System.Windows.Forms.Timer
                  httpTimer.Interval = waitTime
                  httpTimer.Enabled = True
                  onceStarted(httpTimer)
              End Sub
          
              'timer callback
              Private Sub onceStarted(ByVal hTimer As System.Windows.Forms.Timer)
                  Do While [B]hTimer[/B] (missing the required member call to access its current time)
                  Loop
              End Sub

          Comment

          Working...