Exclamation[HELP] Alternative to sleep?

Posts 1–4 of 4 · Page 1 of 1
[HELP] Alternative to sleep?
I like
Code:
Thread.Sleep(X)
except that it has one flaw; it make the program not respond for X amount of time....

is there another way to make it do that without stopping the program completely, just not executing more code until X ammount of time?

I thought about using timers, but I dont know exactly how.....

(Visual Basics 2008)
Code:
Public Class Form1

    Dim x As Integer = 0

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        x += 1

        If x < 10 Then
            'what ever
        End If

        If x = 10 Then
            'continue your code
            x = 0
            Timer1.Enabled = False
        End If
        '10 seconds in this case
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        With Timer1
            .Interval = 1000
            .Enabled = True
        End With
    End Sub
End Class
Newb example but working :P
best bet is to create your own Sleep feature, similar to that of sleep in QBasic.

Here is how to Create your own sleep method which will pause what you want to pause, but still allow the application to function

[php]

Private Sub Sleep(ByVal PauseTime As Double)

Dim Tind As Int16
For Tind = 1 To PauseTime / 50
Threading.Thread.Sleep(50)
Application.DoEvents()
Next

End Sub
[/php]


Note: the Application.DoEvents Will allow your application to function normally during sleep


To use it,

Now you can call a "proper" Sleep

[php]
Sleep(time to sleep)
[/php]


"Added to Snippets Vault Post 1"


thanks both of you

nextgen's is shorter, but blubb, yours is pretty smart


ill probably use both of these sometimes, depending on the situation!
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us