Jump to content

Cpu at 50%


Jac
 Share

Go to solution Solved by JLogan3o13,

Recommended Posts

Here is the code im running on my pc
 
I juste want to check if the program yyy.exe is running 
 
If not im killing program xxx.exe
 
It's alway running at 50% on my vm
 
Is it normal ? 
 
 
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..Program Files (x86)AutoIt3Iconsau3script_v10.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
 
 AutoIt Version: 3.3.12.0
 Author:         myName
 
 Script Function:
Template AutoIt script.
 
#ce ----------------------------------------------------------------------------
 
; Script Start - Add your code below here
 
 
While 1
If Not ProcessExists("xxx.exe") Then
ProcessClose("yyy.exe")
MsgBox(0,"info","xxx Not Running.  Closing yyy")
Exit
Else
If Not ProcessExists("yyy.exe") Then Run("C:Program Files (x86)xxxxxx.exe","C:Program Files (x86)xxx")
EndIf
WEnd
Else
MsgBox($MB_ICONERROR, "", "Launch xxx")
 
EndIf
 
 
Thanks !
 
Link to comment
Share on other sites

  • Moderators
  • Solution

Add a short sleep, like 100ms, to keep your While loop from being so CPU intensive.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

your code is breacking my head ... rly... i dont get the conditional position...

The Wend position is strange ..

it s like there is two way to get the else stat i rly dont get it ... lol

 

you even can do a while of 1 or 2 seconde ... sleep (1000) or (2000) as you usualy need to save memory and CPU on a VM

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's 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

 

Link to comment
Share on other sites

Jac,

See my sig for how to post code.

Your code as posted generates the following when run through Au3Check...

>"C:Program Files (x86)AutoIt3SciTEtidytidy.exe" "C:UsersADMIN010Documentsbb.au3"
Tidy AutoIt3 v14.801.1932.0   Copyright © Jos van der Zande  August 01,2014
"C:UsersADMIN010Documentsbb.au3"(28) : ### Tidy Error: "else" is likely missing it's opening statement. next line creates a negative tablevel.
"C:UsersADMIN010Documentsbb.au3"(31) : ### Tidy Error: "endif" is likely missing it's opening statement. next line creates a negative tablevel.
!> there were  2 error(s) encountered. look in your source for:### Tidy Error:
+> Tidy AutoIt3 finished. Original copied to:"C:UsersADMIN010DocumentsBackUpbb_old3.au3"
>Exit code: 2    Time: 1.53

 

The code also seems illogical.  If XXX is running and YYY is not you will run instances of XXX continuously.  You also need a Sleep somewhere to idle the processor.

If you can define what you are trying to do maybe we can help.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

What your code does:

:begin

IF xxx.exe is not running,

THEN blindly close yyy.exe (which may or may not be running) and exit

ELSE (note: xxx.exe is running!): if yyy.exe is not running, then start xxx.exe

goto :begin

(and then here some unreachable code which is never executed)

In other words, as long as xxx.exe is running and yyy.exe is not running, start another instance of xxx.exe.

In yet other words: if yyy.exe is not running, you are starting addidional instances of xxx.exe as fast as your computer can handle. That must be why your CPU is boiling over. Check your task manager to confirm.

Still, it's hard to guess what you're actually aiming to accomplish with this script, and also it has unreachable code under the WEnd. Did you mean it to be active continuously or just to run it once? Please explain a bit more about the situation you're facing.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

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