Jump to content
Sign in to follow this  
vitimgm01

****Excessive consumption of the CPU****

Recommended Posts

vitimgm01

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

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vitimgm01

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 by vitimgm01

Share this post


Link to post
Share on other sites
water

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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
99ojo

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

Share this post


Link to post
Share on other sites
vitimgm01

It works perfectly, thank you very much!

Share this post


Link to post
Share on other sites
Tvern

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?

Share this post


Link to post
Share on other sites
Ascend4nt

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.

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  

×