Jump to content

Updating clock and sending pings - not at the same time


Recommended Posts

Hi!

I have a script that is 2500 rows right now. I made it into 59 rows now so it's more easier to see.

The script is an App installer - so you check 1-20 checkboxes and select "Install" and the apps starts installing.

To this program I added a clock (that shows HH:MM:SS). I have removed everything except for SS (seconds) so it's easier to see.

I also added a ping request that shows the time in milliseconds. I added the ping request because the "File exists" is so slow when it's to a network folder that is not found... So therefore - if the ping request fails, then it won't even bother to try and find the file. In the example it only points to C-drive though.

The problem now is that the clock is updating every 100ms (I had to do it that often, because if I changed to 500ms, the program for some reason would be very slow to exit?)... But this also means that the ping will be sent every 100ms, and that's not what I want... The ping could be sent every 1-10 seconds or whatever - but it shouldn't ddos attack the server :) 

I've tried and experiment with Adlibregister (but to be honest, I'm really awful in understanding that command) but I can't seem to figure it out... What should I do so that:

  • The clock is updated every 100-500ms.
  • Ping is sent every 1-10 seconds.
  • Exiting the program is quick.
  • I can still use the button "Install" to install the programs (but in this example all it does is a message box ofcourse).

Thank you for your recommendations :)  

 

#RequireAdmin

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <TrayConstants.au3>
#include <ColorConstants.au3>

#Region ### START Koda GUI section ### Form=
Global $Form1_1 = GUICreate("App installer", 1300, 637, -1, -1)
Global $Button1 = GUICtrlCreateButton("Install", 15, 501, 155, 25)
Global $AccessKnown = 0, $iniValue, $Label21 = GUICtrlCreateLabel("Access: ?", 1180, 10, 275, 20)
$Lbl7 = GUICtrlCreateLabel("SS", 583, 600, 30, 61, $SS_CENTER)
Global $PingLabel = GUICtrlCreateLabel("Ping", 1100, 10, 75, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
            GUICtrlSetData($Lbl7, _Seconds())
            Sleep(100)

   Global $PingServer = Ping ('192.168.1.1', 1000)
   If $PingServer Then
      GuiCtrlSetData ($PingLabel, 'Ping: ' & $PingServer & 'ms')
      Global $FileExists = FileExists ('C:/Hello/Hello.txt')
      If $FileExists = 1 Then
      GUICtrlSetData($Label21, "Access: Yes")
            $AccessKnown = 1
      Else
            GUICtrlSetData($Label21, "Access: No")
            $AccessKnown = 0
         EndIf
   Else
      GuiCtrlSetData ($PingLabel, 'Ping: ---')
      GUICtrlSetData($Label21, "Access: No")
      $AccessKnown = 0
   EndIf

   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit

      Case $Button1
         MsgBox (0, "Hello", "Hello world")

    EndSwitch
WEnd


Func _Seconds()
$ss = (@SEC)
Return $ss
EndFunc

 

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