Sign in to follow this  
Followers 0
Dimmak

Sleep less than 1

14 posts in this topic

I use dll function to get sleep(1):

_Sleep(1)
Func _Sleep($ms)
    DllCall($dll_kernel32, "DWORD", "Sleep", "int", $ms)
EndFunc

Function allow to get sleep in range from 0.3 to 1.1ms, but

how to set float sleep ( for examle 0.05ms ) and make it more stable?

Please help!

Share this post


Link to post
Share on other sites



You would like


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Thanx Andreik,

I have tested many examples from your link, but are stable only timer and timer functions ( eat cpu ),

and minimal sleep in range from 0.6 - 1.1ms.

Share this post


Link to post
Share on other sites

Where did you find these ranges? And the parameter of the function is a dword, this mean your value will be truncated if you pass a float.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Where did you find these ranges?

$starttime = _Timer_Init()
_hpSleep(1)
    $endtime = _Timer_Diff($starttime)

And the parameter of the function is a dword, this mean your value will be truncated if you pass a float.

I set integer( for example ):

_Sleep(1)
Func _Sleep($ms)
    DllCall($dll_kernel32, "DWORD", "Sleep", "int", $ms)
EndFunc

But sleep value is between 0.3 ~ 1.1ms.

Share this post


Link to post
Share on other sites

Ok, and what do want to accomplish? This range I'm sure it's variable because of interpreting and other things. It has nothing to do with stability if you set some rounded float values, the result it's not accurate in this way.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

So this is the minimum possible value for autoit!?

I just want to find this out.

Edited by Dimmak

Share this post


Link to post
Share on other sites

It's not AutoIt related as long you call it through DllCall. You don't call a function with what kind of parameters types you want. You must do it according to documentation. If you need to specify a dword then you must do that. If you pass a float the value will be truncated.

When the value is 0:

A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. This behavior changed starting with Windows Server 2003.

When the value is INFINITE:

A value of INFINITE indicates that the suspension should not time out.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

OK! Andreik

I need stable sleep 0.5ms.

Can you help me do this, please!

Share this post


Link to post
Share on other sites

Man you really don't understand you can't pass a float instead of dword in Sleep function from kernel32.dll and then expect to work as you wish?


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Dimmak,

I need stable sleep 0.5ms

There will always be some variablility in the result because of the inherent difference between the timer chips in different machines (jchd explains it much better here) so I do not believe you can ever achieve your target. Add to this the fact that AutoIt needs to interpret the DllCall each time which in itself adds to the variability.... :wacko:

Why do you need such a short Sleep and why is it important for it to be so "stable"? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Andreik

As I know kernel32.dll is not the only one dll in the universe. Maybe other dll...

Melba23

Short sleep need because Autoit works in single thread. And run multiple scripts, the only solution, I think.

Without sleep - very fast, but cpu overload. With sleep slower but less cpu usage. I was looking for a center between these 2 points.

And stable... I just want to know the possibilities of the Autoit. Step by step. One step closer.

Share this post


Link to post
Share on other sites

It's not about name of dll you may use but you must understand that every DllCall it takes some time to be called and this execution time may vary. In this case you cannot make a very accurate sleep.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Yes! I've already realized this. Thanx. :graduated:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0