Jump to content

Poll Info Every 0.5 Seconds


RandomClown
 Share

Recommended Posts

Hai!

======== 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.

O.o?

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

//  Basically syntax looks like this:

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

Thanks for reading

Edited by RandomClown
Link to comment
Share on other sites

  • Moderators

RandomClown,

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
    WEnd
WEnd

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.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Thanks! That seems to be exactly what I need.

I will try it when I get the chance

PS:

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
Link to comment
Share on other sites

@OP

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...