Jump to content
Sign in to follow this  

Poll Info Every 0.5 Seconds

Recommended Posts



======== Details ========

I made a program to poll some info relative to what the user typed.

[as the user types; no submit button]

Since it was a loop, it polled a bazillion time per second. :)

My program took a chunk of CPU power to run [not really, but a hundred times more than it should], so I need a way to have it poll like every second.

I tried sleep, but it lagged the program extremely bad.

When I want to escape it, I hit Esc, but even set to sleep(500), it takes a good 7 seconds to stop [i have to mash or hold esc o.O].

Not sure why it would do that.

Is there a way to fix this loop delay?

======== Summary ========

So to summarize:

The program is working perfectly, except I want to delay its refresh rate.

When I delay it's refresh rate, user inputs are delayed extremely long.


======== Code's syntax ========

//  Basically syntax looks like this:

    poll crap loads of info
    sleep(500)      // I'm pretty sure there is a different form of sleep that I dont know

Thanks for reading

Edited by RandomClown

Share this post

Link to post
Share on other sites


First, welcome to the AutoIt forums.

As you have discovered, using Sleep can make a script very unresponsive - basically because nothing happens during that pause.

There are a couple of ways to make your script a bit more responsive:

1. You could try using something along these lines:

While 1
    ; Poll user input
    $iBegin = TimerInit() ; Get current time
    While TimerDiff($iBegin) < 500 ; Loop until 500 ms have passed
        ; Look for exit buttons etc

The inner loop allows you to look for other keypresses etc while waiting and the user input polling will only take place every .5 sec

2. Use Adlib to run a function every 500ms which polls the user input. Look in the Help file for more details on how to use it - the syntax is very easy.

I hope this helps.


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


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

Thanks! That seems to be exactly what I need.

I will try it when I get the chance


Thanks for the welcome!

I was actually a user on the forums before.

It seems the forums got an upgrade; I had to register my email address again.

Edited by RandomClown

Share this post

Link to post
Share on other sites

I found something else in the help system. [the help feature sucks at finding things]

From the help system, I added a single line to the menu:


& magic happens.

Its awesome

Share this post

Link to post
Share on other sites


why don't you try the adlib functions. There you can specify after how many second should the function for polling data be called. Please check help file for :

AdlibEnable ()

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.