vitimgm01 Posted August 3, 2009 Share Posted August 3, 2009 Hi! I have a program that copies files between two directories and consumes more than 60% of the CPU waiting. What can I do? Thank you Link to comment Share on other sites More sharing options...
water Posted August 3, 2009 Share Posted August 3, 2009 Could you please post your code so we can have a look at it? Makes debugging much easier >_ My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
vitimgm01 Posted August 3, 2009 Author Share Posted August 3, 2009 (edited) I think the error may be here because what other functions and are nothing if not push them to come Opt("GUIOnEventMode", 1) #Region ### ### $Form1_1 = GUICreate("::: ::: E 1.0", 640, 480, -1, -1) GUISetIcon("favicon.ico") GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close") $Button1 = GUICtrlCreateButton("Actualizar", 560, 10, 70, 40, 0) GUICtrlSetOnEvent(-1, "Button1Click") $Combo = GUICtrlCreateCombo("Seleccionar ruta...",33,28, 525, 300) GUICtrlSetOnEvent(-1, "ComboChange") $Button2 = GUICtrlCreateButton("+", 10, 28, 22, 20, 0) GUICtrlSetOnEvent(-1, "Button2Click") $Listado = GUICtrlCreateListView("Archivo|Tamaño|Fecha de modificación",10,60,620, 410,$LVS_SHOWSELALWAYS) _GUICtrlListView_JustifyColumn($Listado, 0,0) _GUICtrlListView_JustifyColumn($Listado, 1,1) _GUICtrlListView_JustifyColumn($Listado, 2,0) GUICtrlSendMsg(-1, 0x101E, 0, 370) GUICtrlSendMsg(-1, 0x101E, 1, 121) GUICtrlSetOnEvent(-1, "ListView1Click") GUISetState(@SW_SHOW) GUISetState(@SW_MINIMIZE);Muestro, minimizo y restauro para liberar memoria ram GUISetState(@SW_RESTORE) #EndRegion ### ### Dim $Archivos Dim $Origen = "" Dim $Destino = "" $Rutas = FileOpen("Rutas.txt",0) If $Rutas = -1 Then MsgBox(0, "Error", "Archivo no se pudo abrir.Se creara uno",8) EndIf Dim $Origenes[_FileCountLines("Rutas.txt")+1] Dim $Destinos[_FileCountLines("Rutas.txt")+1] $Origenes[0] = _FileCountLines("Rutas.txt") $Destinos[0] = _FileCountLines("Rutas.txt") $i=1 While 1 $linea = FileReadLine($Rutas) If @error = -1 then ExitLoop $aux = StringSplit( $linea, "|") $Origenes[$i] = $aux[1] $Destinos[$i] = $aux[2] _GUICtrlComboBox_AddString($Combo, $Origenes[$i] &" --> " & $Destinos[$i]) $i=$i+1 WEnd FileClose($Rutas) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Edited August 3, 2009 by vitimgm01 Link to comment Share on other sites More sharing options...
water Posted August 3, 2009 Share Posted August 3, 2009 (edited) You've created a very tight loop. According to the examples in the AutoIt help file you should insert a Sleep in your code Do Sleep(100) Until GUIGetMsg() = $GUI_EVENT_CLOSE Edited August 3, 2009 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
99ojo Posted August 3, 2009 Share Posted August 3, 2009 I think the error may be here because what other functions and are nothing if not push them to come Opt("GUIOnEventMode", 1) #Region ### ### $Form1_1 = GUICreate("::: ::: E 1.0", 640, 480, -1, -1) GUISetIcon("favicon.ico") GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close") $Button1 = GUICtrlCreateButton("Actualizar", 560, 10, 70, 40, 0) GUICtrlSetOnEvent(-1, "Button1Click") $Combo = GUICtrlCreateCombo("Seleccionar ruta...",33,28, 525, 300) GUICtrlSetOnEvent(-1, "ComboChange") $Button2 = GUICtrlCreateButton("+", 10, 28, 22, 20, 0) GUICtrlSetOnEvent(-1, "Button2Click") $Listado = GUICtrlCreateListView("Archivo|Tamaño|Fecha de modificación",10,60,620, 410,$LVS_SHOWSELALWAYS) _GUICtrlListView_JustifyColumn($Listado, 0,0) _GUICtrlListView_JustifyColumn($Listado, 1,1) _GUICtrlListView_JustifyColumn($Listado, 2,0) GUICtrlSendMsg(-1, 0x101E, 0, 370) GUICtrlSendMsg(-1, 0x101E, 1, 121) GUICtrlSetOnEvent(-1, "ListView1Click") GUISetState(@SW_SHOW) GUISetState(@SW_MINIMIZE);Muestro, minimizo y restauro para liberar memoria ram GUISetState(@SW_RESTORE) #EndRegion ### ### Dim $Archivos Dim $Origen = "" Dim $Destino = "" $Rutas = FileOpen("Rutas.txt",0) If $Rutas = -1 Then MsgBox(0, "Error", "Archivo no se pudo abrir.Se creara uno",8) EndIf Dim $Origenes[_FileCountLines("Rutas.txt")+1] Dim $Destinos[_FileCountLines("Rutas.txt")+1] $Origenes[0] = _FileCountLines("Rutas.txt") $Destinos[0] = _FileCountLines("Rutas.txt") $i=1 While 1 $linea = FileReadLine($Rutas) If @error = -1 then ExitLoop $aux = StringSplit( $linea, "|") $Origenes[$i] = $aux[1] $Destinos[$i] = $aux[2] _GUICtrlComboBox_AddString($Combo, $Origenes[$i] &" --> " & $Destinos[$i]) $i=$i+1 WEnd FileClose($Rutas) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Hi, just put a Sleep (20) in your while loop. ;-) Stefan Link to comment Share on other sites More sharing options...
vitimgm01 Posted August 3, 2009 Author Share Posted August 3, 2009 It works perfectly, thank you very much! Link to comment Share on other sites More sharing options...
Tvern Posted August 3, 2009 Share Posted August 3, 2009 I was under the impression that you should avoid using sleep in a GUIGetMsg() loop because it can cause the GUI to become unresponsive.GUIGetMsg()This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU.Or does this only apply when GUIGetMsg() is actually inside the loop? Link to comment Share on other sites More sharing options...
Ascend4nt Posted August 3, 2009 Share Posted August 3, 2009 I was under the impression that you should avoid using sleep in a GUIGetMsg() loop because it can cause the GUI to become unresponsive.Or does this only apply when GUIGetMsg() is actually inside the loop?Actually, sleep() works in milliseconds, and 1000 of those equals one second, so very small amounts won't be noticeable for most - plus Windows creates a big queue for all the messages sent to a program - and AutoIT (or the default handler) handles most of them, even when GuiGetMsg() isn't called. Don't worry about an app getting a 'hung' status either - that doesn't usually happen for like 5 seconds of not responding to messages..MSDN:An application is considered to be not responding if it is not waiting for input, is not in startup processing, and has not called PeekMessage within the internal timeout period of 5 seconds. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) 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