Hi
I need to find a way to pause for milisceonds but not using thread.sleep
what options are there ?
I want to make labels fly around the window at a “certain speed” and I thougt of something like this
for i=x1 to x2
labe.left=x1
SLEEP n miliseconds
next
I tried using threads but threads cannot acces controls otherwise they will raise an ecception.
You can set the period of a timer with millisecond precision (1/1000th of a second). It just defaults to 1 second when you first drag it onto a window in the IDE.
On VB6 there s an API called Sleep (miliseconds) but I noticed that the “speed” depended mostly on CPU power rather than real miliseconds…[/quote]
That is what Michel’s function does, but it should be avoided if possible in Xojo to prevent the UI from freezing.
On VB6 there s an API called Sleep (miliseconds) but I noticed that the “speed” depended mostly on CPU power rather than real miliseconds…[/quote]
Sleep as VB6 does or as the method I posted for you both do is typically procedural. It does not give a chance to the application multitasking to take place. While it executes it holds everything. So it is easy to use and understand, but chances are it will make your application unresponsive if your application lasts too long.
You may want instead to place your animation within a timer, and set the timer period to regulate speed.
Sub Sleep(Mil as integer)
dim old as double = microseconds
for i as integer = 1 to Mil*1000
App.YieldToNextThread
self.refresh
if microseconds-old >= Mil*1000 then exit
next
return
End Sub
// Label1
Sub Open()
Me.Text = CurrentMethodName
End Sub
// Timer1, drag from the Library onto the window and set the following properties in the IDE
// - Mode = Multiple
// - Period = 1500 (milliseconds)
Sub Action()
Label1.Left = Rnd.InRange(0, Width)
Label1.Top = Rnd.InRange(0, Height)
End Sub
// Label1
Sub Open()
Me.Text = CurrentMethodName
End Sub
// Timer1, drag from the Library onto the window and set the following properties in the IDE
// - Mode = Multiple
// - Period = 1500 (milliseconds)
Sub Action()
Label1.Left = Rnd.InRange(0, Width)
Label1.Top = Rnd.InRange(0, Height)
End Sub
End Class[/code][/quote]
Eli, I am sorry, but I do not understand how you obtain the equivalent of app.SleepCurrentThread(1000)