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. Sleep not working right?

Sleep not working right?

Scheduled Pinned Locked Moved Visual Basic
helpgame-devquestion
3 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
    MadCow
    wrote on last edited by
    #1

    I'm having a problem that has me a bit confused. Maybe somebody out there can help me a bit. I am making an adventure type fighting game and am using a listbox to display the combat results. My combat routine is contained within a function that calculates inititive, hitting, damage and whatnot. Right now all the info gets displayed all in one shot. What I want is to add a delay between the initiative and attacking messages. What I've tried is a simple for next loop, but for some reason this has no effect. So I tried the 'System.Threading.Thread.Sleep(2000)'method and this seems to create a pause. However it seems to run at the beginning of the function even though I put it halfway into my function. Why is the .sleep method getting run first? Hopefully this makes sense. thanks.

    D 1 Reply Last reply
    0
    • M MadCow

      I'm having a problem that has me a bit confused. Maybe somebody out there can help me a bit. I am making an adventure type fighting game and am using a listbox to display the combat results. My combat routine is contained within a function that calculates inititive, hitting, damage and whatnot. Right now all the info gets displayed all in one shot. What I want is to add a delay between the initiative and attacking messages. What I've tried is a simple for next loop, but for some reason this has no effect. So I tried the 'System.Threading.Thread.Sleep(2000)'method and this seems to create a pause. However it seems to run at the beginning of the function even though I put it halfway into my function. Why is the .sleep method getting run first? Hopefully this makes sense. thanks.

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

      This is happening because your thread gets puts to sleep before your window has a chance to update. What you need to do is put an 'Application.DoEvents()' just before the Sleep statement and that should take care of it. RageInTheMachine9532

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This is happening because your thread gets puts to sleep before your window has a chance to update. What you need to do is put an 'Application.DoEvents()' just before the Sleep statement and that should take care of it. RageInTheMachine9532

        M Offline
        M Offline
        MadCow
        wrote on last edited by
        #3

        Awesome! Now it works the way I want it. Thanks.

        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