Results 1 to 3 of 3

Thread: thread pausing

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    thread pausing

    I am wondering if anyone has encountered a time in which they would pause a thread for longer than 60 seconds? Right now, when I pause a thread and let it go for longer than 60 seconds, it will cause a warning (something about pumping messages). I know I can just continue with the program, but I doubt it's really safe to keep doing this, and what happens when I release the application live without debugging?
    Is there anyway around this, or is it ok to just leave it as is?

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: thread pausing

    If it is the UI thread, I'd say it is a problem. If not then try this

    Code:
            Dim stpw As New Stopwatch
            Dim howLongToReallySleep As New TimeSpan(0, 1, 0) 'one minute
    
            'where you have thread.sleep 60 secs. replace with
            stpw.Reset() 'start the clock
            stpw.Start()
            Do
                Try
                    Threading.Thread.Sleep(100)
                Catch
                End Try
            Loop While stpw.Elapsed < howLongToReallySleep
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: thread pausing

    Why exactly are you sleeping a thread that long anyway? Normally the only reason you'd sleep for a long time is because you're waiting for something to happen. In that case though, you'd normally sleep for short periods of time and poll repeatedly to see if the thing you were waiting for had occurred. Otherwise you might be sleeping for a long time after you could have proceeded. That is generally best avoided too though. If you explain what you're actually trying to achieve then we can provide the best advice on how to achieve it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width