Jump to content

Recommended Posts

Posted

I'm making a Traymenu in systray to initiate a certain function automatically based on changes in @ipaddress. The While loop uses about 2-4 cpu constantly.

Example:

While 1
    $msg = TrayGetMsg()
    Select
  Case $msg = 0
   If $ipstring <> @IPAddress1 & @IPAddress2 & @IPAddress3 & @IPAddress4 Then _CheckIPs()
            ContinueLoop
        Case $msg = $connect
            _Connect()
   TrayItemSetState($connect, $tray_unchecked)
  Case $msg = $disconnect
   _Disconnect()
   EndIf
  ;Case $msg = $exititem
         ;   ExitLoop
EndSelect

WEnd

$ipstring = @IPAddress1 & @IPAddress2 & @IPAddress3 & @IPAddress4 is set inside _CheckIPs().

I've tried different solutins, but it seems that everything I try will utilize 2-4% CPU. I've also tried _DateDiff() before the $ipstring check, but _NowCalc() also uses CPU.

Anyone got any ideas on how to solve this without utilizing the CPU?

Posted

I've noticed this in an application I created too, add a sleep (e.g. Sleep(20) )in there to see if it reduces the amount, though 2-4% isn't that much in all honesty.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 3/14/2012 at 11:53 AM, 'guinness said:

I've noticed this in an application I created too, add a sleep (e.g. Sleep(20) )in there to see if it reduces the amount, though 2-4% isn't that much in all honesty.

Thanks. A Sleep() did make the CPU utilization go down. Another option would be to run 2 processes. One traymenu to Connect and Disconnect, and another one to monitor the IPAddresses.

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
×
×
  • Create New...