ppat Posted November 5, 2009 Share Posted November 5, 2009 Hi,I want to make a very simple control with 2 buttons. The control window never closes unless clicking on the top right x. When one button is clicked, it will change a value in an .ini file.My code looks like this; Run the GUI until the dialog is closed using the top right xWhile 1$msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 ; Change the ini file here using IniRead, IniWrite Case $msg = $Button_2 ; Change the ini file here using IniRead, IniWrite EndSelectWEndI click on one of the buttons maybe once, twice a day, but the control remains open all day long. I recently noticed that at the end of the day, the performance of my PC decreases. I wonder if it is due to this program and the while loop executing in the background for a full day. Is there a better way to do this than using the infinite while loop? Link to comment Share on other sites More sharing options...
Mison Posted November 5, 2009 Share Posted November 5, 2009 (edited) I think there is another way that's called Event Mode(I'm not sure, I can hardly remember..) You can try insert Sleep(10) just before the Wend.. It can reduces mamory usage... Edited November 5, 2009 by Mison Hi ;) Link to comment Share on other sites More sharing options...
trancexx Posted November 5, 2009 Share Posted November 5, 2009 I think there is another way that's called Event Mode(I'm not sure, I can hardly remember..)You can try insert Sleep(10) just before the Wend.. It can reduces mamory usage...And you could stop writing shitty advices. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 5, 2009 Moderators Share Posted November 5, 2009 ppat,You must have an infinite While...WEnd loop somewhere in your script or it ends! And this is true in MessageLoop and OnEvent mode.I strongly doubt that it is your script that is causing your perceived "slowdown" problem, but there are a couple of basic things you can do to see if it is giving you a problem:Once you have launched your script, open Task Manager and look at the information for your script under the "Process" tab. Note the CPU and Memory(Private Working Set) values. At the end of the day - when you sense the PC is sluggish - look again at these values.The CPU figure shows how much of the processor you are using. With a GUIGetMsg() in your loop, you should be down at 0-2. I do not really expect this to change with time - but you never know!The Memory number shows how much of the limited (a relative term) amount available your app is using. If you are using the standard Autoit functions to do your ini stuff you should not have problem with memory leakage - but this is a way to check. If the number has increased markedly, then you should post your code so we can try and see where the problem might lie.Of course, you might like to do the same thing for the other processes running - you may well find the culprit elsewhere! 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...
jvanegmond Posted November 5, 2009 Share Posted November 5, 2009 Hi,I want to make a very simple control with 2 buttons. The control window never closes unless clicking on the top right x. When one button is clicked, it will change a value in an .ini file.My code looks like this; Run the GUI until the dialog is closed using the top right xWhile 1$msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 ; Change the ini file here using IniRead, IniWrite Case $msg = $Button_2 ; Change the ini file here using IniRead, IniWrite EndSelectWEndI click on one of the buttons maybe once, twice a day, but the control remains open all day long. I recently noticed that at the end of the day, the performance of my PC decreases. I wonder if it is due to this program and the while loop executing in the background for a full day. Is there a better way to do this than using the infinite while loop?Hi,AutoIt can use an "events mode" so the script does not have to do while loops. Internally, AutoIt still does the while loop, but this in the C++ code (makes no difference, in the end). Using events mode will not solve your problem.The script you have written has no long term performance issues on your computer. You can try this out for yourself, simply don't run the script and see how your PC is behaving after a full day. I can already predict the outcome with a vast amount of certainty: Your script is fine.You shouldn't worry about these things. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Mison Posted November 5, 2009 Share Posted November 5, 2009 And you could stop writing shitty advices.Oh, come on, I've got that from Manadar you know.. about that Sleep(10) Hi ;) Link to comment Share on other sites More sharing options...
jvanegmond Posted November 5, 2009 Share Posted November 5, 2009 Oh, come on, I've got that from Manadar you know.. about that Sleep(10)I never said that.1. GUIGetMsg() has an in-built sleep. When you are calling it in a loop, you don't have to additionally call a sleep.2. Sleep can help fast loops that do polling to slow down. For example, in a TCP server when you are waiting for clients. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Mison Posted November 5, 2009 Share Posted November 5, 2009 (edited) You never said that? ermmm... Seems like I had misinterpreted your post here... PostAfter read that post, I was really thinking that Sleep = less mamory... I guess I was wrong in that assumptionI'm sorry ok... Edited November 5, 2009 by Mison Hi ;) Link to comment Share on other sites More sharing options...
jvanegmond Posted November 5, 2009 Share Posted November 5, 2009 I specifically said: Sleep == Less CPU usage.This has nothing to do with memory. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Mison Posted November 5, 2009 Share Posted November 5, 2009 Damn… all this while, I thought that mamory usage == CPU usage... ok ok, I am really a noob, hope you all can forgive me for what I had been said, ok? Thanks for making that distinction clear for me Hi ;) Link to comment Share on other sites More sharing options...
Bert Posted November 5, 2009 Share Posted November 5, 2009 In the past, I've used the sleep trick to cut down on CPU usage. The real cause was badly written code on my part, but then again one has to remember coding is an art, and a dark art at that. I could give a piece of code to one of the MVPs, and I'm sure they could make it different, but do the same thing. What they do may not be better, but it would work. Personally, I would not criticize one person's preference in using it. The Vollatran project My blog: http://www.vollysinterestingshit.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