RandomClown Posted October 26, 2009 Share Posted October 26, 2009 (edited) 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 October 26, 2009 by RandomClown Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 26, 2009 Moderators Share Posted October 26, 2009 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 WEndThe inner loop allows you to look for other keypresses etc while waiting and the user input polling will only take place every .5 sec2. 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
RandomClown Posted October 29, 2009 Author Share Posted October 29, 2009 (edited) Thanks! That seems to be exactly what I need.I will try it when I get the chancePS: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 October 29, 2009 by RandomClown Link to comment Share on other sites More sharing options...
RandomClown Posted November 3, 2009 Author Share Posted November 3, 2009 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:GUISetOnEvent($GUI_EVENT_CLOSE,"Quit")& magic happens.Its awesome Link to comment Share on other sites More sharing options...
Manjish Posted November 3, 2009 Share Posted November 3, 2009 @OPwhy 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now