Jump to content
cookiemonster

Form freezes while trying to resolve IP

Recommended Posts

cookiemonster

Hi,

I have a form which calls this function:

Func HostToIP($Host, $Label)
TCPStartup()
    Local $sIPAddress = TCPNameToIP($Host)
    If @error Then
        GUICtrlSetData ($Label, "Error code: " & @error)
    Else
        GUICtrlSetData ($Label, $sIPAddress)
    EndIf
TCPShutdown()
EndFunc

But if it cannot resolve the host to an IP, the whole form freezes for a few seconds until the TCPNameToIP times out, how can I stop the form from freezing whilst it waits for the host to ip times out?

TCPNameToIP is part of #include <_sql.au3>

Share this post


Link to post
Share on other sites
AutoBert

Couldn't ack.  Tested with:

$tdStart=TimerInit()
            TCPStartup()
            $sIPAddress = TCPNameToIP("www.autoitscript2.com")
            If @error Then
                GUICtrlSetData($Label, "Error code: " & @error)
            Else
                GUICtrlSetData($Label, $sIPAddress)
            EndIf
            TCPShutdown()
            ConsoleWrite('Time for resolve: '&TimerDiff($tdStart)&@CRLF)

consoleoutput:

Quote

Time for resolve: 25.8624331039144

TCPNameToIP is a native AutoIt func.

 

Post a full runable reproducer script showing your issue.

Share this post


Link to post
Share on other sites
cookiemonster
23 minutes ago, AutoBert said:

Post a full runable reproducer script showing your issue.

Heres a full working script where it freezes:

#NoTrayIcon
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Sound.au3>
#include <MetroGUI-UDF\MetroGUI_UDF.au3>
#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <_sql.au3>

#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe
#AutoIt3Wrapper_Res_HiDpi=y

_SetTheme("DarkBlueV2")

_Metro_EnableHighDPIScaling()

Local $ServerAddress = "SomeServer"

$GLOBAL_MAIN_GUI = _Metro_CreateGUI("Settings", 347, 532, 950, -1, True)

GUISetFont ( 9 , 0 , 0 , "Segoe UI" , $GLOBAL_MAIN_GUI , 5 )
GUICtrlSetDefColor ( $COLOR_WHITE , $GLOBAL_MAIN_GUI )

GUICtrlCreateGroup("", 8, 35, 330, 142)
GUICtrlCreateLabel("IP", 24, 80)

$IP = GUICtrlCreateLabel("", 130, 80, 193, 21, $SS_RIGHT)

$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, True)

$GUI_CLOSE_BUTTON = $Control_Buttons[0]
GUICtrlSetTip($GUI_CLOSE_BUTTON, "Close")
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]

Dim $MenuButtonsArray[4] = ["Settings", "About", "Contact", "Exit"]

GUISetState(@SW_SHOW)

HostToIP($ServerAddress, $IP)

While 1
    _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON
            Exit
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $GUI_MENU_BUTTON
            Local $MenuSelect = _Metro_MenuStart($GLOBAL_MAIN_GUI, $GUI_MENU_BUTTON, 150, $MenuButtonsArray, "Segoe UI", 9, 0)
            Switch $MenuSelect
                Case "0"
                    MsgBox (4096,"1","2")
                Case "1"
                    ConsoleWrite("Returned 1 = About button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = Contact button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Exit button clicked." & @CRLF)
                    _Metro_GUIDelete($GLOBAL_MAIN_GUI)
                    Exit
            EndSwitch
    EndSwitch
WEnd

Func HostToIP($Host, $Label)
TCPStartup()
    Local $sIPAddress = TCPNameToIP($Host)
    If @error Then
        GUICtrlSetData ($Label, "Error code: " & @error)
    Else
        GUICtrlSetData ($Label, $sIPAddress)
    EndIf
TCPShutdown()
EndFunc

 

Share this post


Link to post
Share on other sites
AutoBert

this script isn't working:

+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
! Invalid AutoIt3Wrapper directive Keyword:#AutoIt3Wrapper_Res_HiDpi with value:y
>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(50,44) : error: _Metro_HoverCheck_Loop() called with wrong number of args.
    _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF.au3"(558,80) : REF: definition of _Metro_HoverCheck_Loop().
Func _Metro_HoverCheck_Loop(ByRef $GUI_HOVER_REG, $Metro_GUI, $Metro_GUI_2 = 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(68,54) : error: _Metro_GUIDelete() called with wrong number of args.
                    _Metro_GUIDelete($GLOBAL_MAIN_GUI)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF.au3"(317,44) : REF: definition of _Metro_GUIDelete().
Func _Metro_GUIDelete($GUI_HOVER_REG, $GUI)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(18,29) : error: _Metro_EnableHighDPIScaling(): undefined function.
_Metro_EnableHighDPIScaling()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(32,75) : error: _Metro_AddControlButtons(): undefined function.
$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, True)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(58,126) : error: _Metro_MenuStart(): undefined function.
            Local $MenuSelect = _Metro_MenuStart($GLOBAL_MAIN_GUI, $GUI_MENU_BUTTON, 150, $MenuButtonsArray, "Segoe UI", 9, 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3 - 5 error(s), 0 warning(s)
!>12:56:52 AU3Check ended. Press F4 to jump to next error.rc:2
+>12:56:52 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 2.253

attach your (modified?) version of MetroGUI_UDF.au3 and if any func of _sql.au3 this also.

Share this post


Link to post
Share on other sites
cookiemonster
7 minutes ago, AutoBert said:

attach your (modified?) version of MetroGUI_UDF.au3 and if any func of _sql.au3 this also.

Attached MetroGUI_UDF.au3, however i havnt modified it at all.

No func for _sql.au3 at present, it freeze for me as it is in the code above.

MetroGUI_UDF.au3

Share this post


Link to post
Share on other sites
AutoBert

Now this errors:

+>13:17:44 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0407)
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3"(141,43) : warning: $GLOBAL_GUI_LIST: possibly used before declaration.
    For $iGUIs = 0 To UBound($GLOBAL_GUI_LIST)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3"(315,56) : error: _GetDesktopWorkArea() called with wrong number of args.
    Local $FullScreenPOS = _GetDesktopWorkArea($mGUI, True)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroUDF-Required\BorderlessWinUDF.au3"(188,32) : REF: definition of _GetDesktopWorkArea().
Func _GetDesktopWorkArea($hWnd)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3"(185,55) : error: INTERNAL_INTERCEPT_FRAMEDRAW(): undefined function.
    GUIRegisterMsg(0x0083, "INTERNAL_INTERCEPT_FRAMEDRAW")
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3 - 2 error(s), 1 warning(s)
!>13:17:46 AU3Check ended. Press F4 to jump to next error.rc:2
+>13:17:46 AutoIt3Wrapper Finished.

So last try: post link to used version of the MetroGuiUDF

Edit: i know GUI's created with native AutoIt won't freeze, maybe the author of the UDF has some bugs.

 

 

Edited by AutoBert

Share this post


Link to post
Share on other sites
cookiemonster
3 minutes ago, AutoBert said:

So last try: post link to used version of the MetroGuiUDF

I downloaded it from:

Its version 4.3 i believe

Share this post


Link to post
Share on other sites
AutoBert

Ok, yet i can ack, needed time with this UDF  2318 ms this is ~ 100* as in a normal GUI. But if you call before GuiSetState the user didn't notice it. 

 

Share this post


Link to post
Share on other sites
cookiemonster
22 minutes ago, AutoBert said:

Ok, yet i can ack, needed time with this UDF  2318 ms this is ~ 100* as in a normal GUI. But if you call before GuiSetState the user didn't notice it. 

User needs to be able to see the window from the very start, it will later have a refresh button which will call the same function again, and I wouldnt want it freezing when doing the function again after pressing refresh button

47 minutes ago, AutoBert said:

Edit: i know GUI's created with native AutoIt won't freeze, maybe the author of the UDF has some bugs.
 

I have stripped it down to basics, its now using native autoit, but still freezes:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

Local $SERVERADDRESS = "SomeServer"

GUICreate("", 395, 532, 598, 0)

GUICtrlCreateLabel("IP: ", 24, 56, 20, 17)

$JEFF_IP = GUICtrlCreateLabel("", 120, 56, 249, 21)

GUISetState(@SW_SHOW)

HostToIP($ServerAddress)

Func HostToIP($Server)
TCPStartup()
    Local $sIPAddress = TCPNameToIP($Server)
    If @error Then
        GUICtrlSetData ($JEFF_IP, "Error code: " & @error)
    Else
        GUICtrlSetData ($JEFF_IP, $sIPAddress)
    EndIf
TCPShutdown()
EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites
AutoBert

Tested with:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>


TCPStartup()
Local $SERVERADDRESS = "www.autoitscript2.com"

GUICreate("", 395, 532, 598, 0)
$idResolve=GUICtrlCreateButton('&IP',5,5,100,21)
GUICtrlCreateLabel("IP: ", 24, 56, 20, 17)

$JEFF_IP = GUICtrlCreateLabel("", 120, 56, 249, 21)

GUISetState(@SW_SHOW)

;HostToIP($SERVERADDRESS)

Func HostToIP($Server)
    $tdStart = TimerInit()
    $sIPAddress = TCPNameToIP($SERVER)
    If @error Then
        GUICtrlSetData($JEFF_IP, "Error code: " & @error)
    Else
        GUICtrlSetData($JEFF_IP, $sIPAddress)
    EndIf
    ConsoleWrite('Time for resolve: ' & TimerDiff($tdStart) & @CRLF)
EndFunc   ;==>HostToIP

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            TCPShutdown()
            Exit
        Case $idResolve
            HostToIP($SERVERADDRESS)
    EndSwitch
WEnd

console output:

Time for resolve: 27.7536355246535
Time for resolve: 2.48640318259607
Time for resolve: 2.83392362742224
Time for resolve: 2.59456332104105

 

Edited by AutoBert

Share this post


Link to post
Share on other sites
AutoBert

Meanwhile tested with:

==============================================================================================
; Name ..........: MetroGUI UDF Example
; Version .......: v4.3
; Author ........: BB_19
; ===============================================================================================================================

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y

#NoTrayIcon
#include "MetroGUI-UDF\MetroGUI_UDF.au3"

;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

            TCPStartup()
;Create resizable Metro GUI
$Form1 = _Metro_CreateGUI("Example", 500, 300, -1, -1, True)

;Add/create control buttons to the GUI
$Control_Buttons = _Metro_AddControlButtons(True, True, True, True, True) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
;======================================================================================================================================================================

;Create  Buttons
$Button1 = _Metro_CreateButton("Button Style 1", 105, 245, 130, 40)
$Button2 = _Metro_CreateButtonEx("Button Style 2", 255, 245, 130, 40)


;Create an Array containing menu button names
Dim $MenuButtonsArray[4] = ["Settings", "About", "Contact", "Exit"]

;Set resizing options for the controls so they don't change in size or position. This can be customized to match your gui perfectly for resizing. See AutoIt Help file.
GUICtrlSetResizing($Button1, 768 + 8)
GUICtrlSetResizing($Button2, 768 + 8)
$IP = GUICtrlCreateLabel("", 130, 55, 193, 21)
GUICtrlSetColor(-1,0xffffff)
GUISetState(@SW_SHOW)

Local $SERVERADDRESS = "www.autoitscript2.com"

While 1
    _Metro_HoverCheck_Loop($Form1) ;This hover check has to be added to the main While loop, otherwise the hover effects won't work.
    $nMsg = GUIGetMsg()
    Switch $nMsg
        ;=========================================Control-Buttons===========================================
        Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON
            _Metro_GUIDelete($Form1) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs!
            TCPShutdown()
            Exit
        Case $GUI_MAXIMIZE_BUTTON
            GUISetState(@SW_MAXIMIZE)
        Case $GUI_RESTORE_BUTTON
            GUISetState(@SW_RESTORE)
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $GUI_FULLSCREEN_BUTTON, $GUI_FSRestore_BUTTON
            _Metro_FullscreenToggle($Form1, $Control_Buttons)
            ;===================================================================================================
        Case $GUI_MENU_BUTTON
            Local $MenuSelect = _Metro_MenuStart($Form1, $GUI_MENU_BUTTON, 150, $MenuButtonsArray, "Segoe UI", 9, 0) ; Opens the metro Menu. See decleration of $MenuButtonsArray above.
            Switch $MenuSelect ;Above function returns the index number of the selected button from the provided buttons array.
                Case "0"
                    ConsoleWrite("Returned 0 = Settings button clicked." & @CRLF)
                Case "1"
                    ConsoleWrite("Returned 1 = About button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = Contact button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Exit button clicked." & @CRLF)
                    _Metro_GUIDelete($Form1)
                    Exit
            EndSwitch
        Case $Button2
            _GUIDisable($Form1, 0, 30) ;For better visibility of the MsgBox on top of the first GUI.
            _Metro_MsgBox(0, "Metro MsgBox Example", "Button 2 clicked. (Button with 3 secs timeout)", 400, 11, $Form1, 3) ; with 3 secs timeout
            _GUIDisable($Form1)
        Case $Button1
            #cs
            _GUIDisable($Form1, 0, 30)
            _Metro_MsgBox(0, "Metro MsgBox Example", "Press ok to set progressbar.", 350, 11, $Form1)
            _GUIDisable($Form1)
            For $i = 0 To 85 Step +2
                Sleep(1)
                _Metro_SetProgress($Progress1, $i)
            Next
            _GUIDisable($Form1, 0, 30)
            Local $Select_YesNo = _Metro_MsgBox(4, "Metro MsgBox Example", "Select yes to create a second GUI.", 350, 11, $Form1)
            If $Select_YesNo = "Yes" Then _SecondGUI()
            _GUIDisable($Form1)
            #ce
            HostToIP($SERVERADDRESS)
    EndSwitch
WEnd


Func _SecondGUI()
    Local $Form2 = _Metro_CreateGUI("Example2", 600, 400, -1, -1, True)

    ;Add control buttons
    Local $Control_Buttons_2 = _Metro_AddControlButtons(True, True, True, True)

    ;Set variables for control buttons
    Local $GUI_CLOSE_BUTTON = $Control_Buttons_2[0]
    Local $GUI_MAXIMIZE_BUTTON = $Control_Buttons_2[1]
    Local $GUI_RESTORE_BUTTON = $Control_Buttons_2[2]
    Local $GUI_MINIMIZE_BUTTON = $Control_Buttons_2[3]
    Local $GUI_FULLSCREEN_BUTTON = $Control_Buttons_2[4]
    Local $GUI_FSRestore_BUTTON = $Control_Buttons_2[5]
    Local $Button1 = _Metro_CreateButton("Close", 250, 340, 100, 40)
    GUICtrlSetResizing($Button1, 768 + 8)
    GUISetState(@SW_SHOW)

    While 1
        _Metro_HoverCheck_Loop($Form2) ;Add hover check in loop
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON, $Button1
                _Metro_GUIDelete($Form2) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs!
                Return 0
            Case $GUI_MAXIMIZE_BUTTON
                GUISetState(@SW_MAXIMIZE)
            Case $GUI_RESTORE_BUTTON
                GUISetState(@SW_RESTORE)
            Case $GUI_MINIMIZE_BUTTON
                GUISetState(@SW_MINIMIZE)
            Case $GUI_FULLSCREEN_BUTTON, $GUI_FSRestore_BUTTON
                _Metro_FullscreenToggle($Form2, $Control_Buttons_2)
        EndSwitch
    WEnd
EndFunc   ;==>_SecondGUI

Func HostToIP($Server)
    $tdStart = TimerInit()
    $sIPAddress = TCPNameToIP($SERVER)
    If @error Then
        GUICtrlSetData($IP, "Error code: " & @error)
    Else
        GUICtrlSetData($IP, $sIPAddress)
    EndIf
    ConsoleWrite('Time for resolve: ' & TimerDiff($tdStart) & @CRLF)
EndFunc   ;==>HostToIP

 

also no problems:

Time for resolve: 37.4138078896741
Time for resolve: 4.10688525681313
Time for resolve: 3.32032425001504

the problem is TCPNameToIP, if used with a string that isn't a URL  than it's frozen using a non existing  URL it resolve fast.   So @BB_19 did good job.

Edited by AutoBert

Share this post


Link to post
Share on other sites
cookiemonster
On 30/07/2016 at 2:21 PM, AutoBert said:

Meanwhile tested with:

==============================================================================================
; Name ..........: MetroGUI UDF Example
; Version .......: v4.3
; Author ........: BB_19
; ===============================================================================================================================

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y

#NoTrayIcon
#include "MetroGUI-UDF\MetroGUI_UDF.au3"

;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

            TCPStartup()
;Create resizable Metro GUI
$Form1 = _Metro_CreateGUI("Example", 500, 300, -1, -1, True)

;Add/create control buttons to the GUI
$Control_Buttons = _Metro_AddControlButtons(True, True, True, True, True) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
;======================================================================================================================================================================

;Create  Buttons
$Button1 = _Metro_CreateButton("Button Style 1", 105, 245, 130, 40)
$Button2 = _Metro_CreateButtonEx("Button Style 2", 255, 245, 130, 40)


;Create an Array containing menu button names
Dim $MenuButtonsArray[4] = ["Settings", "About", "Contact", "Exit"]

;Set resizing options for the controls so they don't change in size or position. This can be customized to match your gui perfectly for resizing. See AutoIt Help file.
GUICtrlSetResizing($Button1, 768 + 8)
GUICtrlSetResizing($Button2, 768 + 8)
$IP = GUICtrlCreateLabel("", 130, 55, 193, 21)
GUICtrlSetColor(-1,0xffffff)
GUISetState(@SW_SHOW)

Local $SERVERADDRESS = "www.autoitscript2.com"

While 1
    _Metro_HoverCheck_Loop($Form1) ;This hover check has to be added to the main While loop, otherwise the hover effects won't work.
    $nMsg = GUIGetMsg()
    Switch $nMsg
        ;=========================================Control-Buttons===========================================
        Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON
            _Metro_GUIDelete($Form1) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs!
            TCPShutdown()
            Exit
        Case $GUI_MAXIMIZE_BUTTON
            GUISetState(@SW_MAXIMIZE)
        Case $GUI_RESTORE_BUTTON
            GUISetState(@SW_RESTORE)
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $GUI_FULLSCREEN_BUTTON, $GUI_FSRestore_BUTTON
            _Metro_FullscreenToggle($Form1, $Control_Buttons)
            ;===================================================================================================
        Case $GUI_MENU_BUTTON
            Local $MenuSelect = _Metro_MenuStart($Form1, $GUI_MENU_BUTTON, 150, $MenuButtonsArray, "Segoe UI", 9, 0) ; Opens the metro Menu. See decleration of $MenuButtonsArray above.
            Switch $MenuSelect ;Above function returns the index number of the selected button from the provided buttons array.
                Case "0"
                    ConsoleWrite("Returned 0 = Settings button clicked." & @CRLF)
                Case "1"
                    ConsoleWrite("Returned 1 = About button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = Contact button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Exit button clicked." & @CRLF)
                    _Metro_GUIDelete($Form1)
                    Exit
            EndSwitch
        Case $Button2
            _GUIDisable($Form1, 0, 30) ;For better visibility of the MsgBox on top of the first GUI.
            _Metro_MsgBox(0, "Metro MsgBox Example", "Button 2 clicked. (Button with 3 secs timeout)", 400, 11, $Form1, 3) ; with 3 secs timeout
            _GUIDisable($Form1)
        Case $Button1
            #cs
            _GUIDisable($Form1, 0, 30)
            _Metro_MsgBox(0, "Metro MsgBox Example", "Press ok to set progressbar.", 350, 11, $Form1)
            _GUIDisable($Form1)
            For $i = 0 To 85 Step +2
                Sleep(1)
                _Metro_SetProgress($Progress1, $i)
            Next
            _GUIDisable($Form1, 0, 30)
            Local $Select_YesNo = _Metro_MsgBox(4, "Metro MsgBox Example", "Select yes to create a second GUI.", 350, 11, $Form1)
            If $Select_YesNo = "Yes" Then _SecondGUI()
            _GUIDisable($Form1)
            #ce
            HostToIP($SERVERADDRESS)
    EndSwitch
WEnd


Func _SecondGUI()
    Local $Form2 = _Metro_CreateGUI("Example2", 600, 400, -1, -1, True)

    ;Add control buttons
    Local $Control_Buttons_2 = _Metro_AddControlButtons(True, True, True, True)

    ;Set variables for control buttons
    Local $GUI_CLOSE_BUTTON = $Control_Buttons_2[0]
    Local $GUI_MAXIMIZE_BUTTON = $Control_Buttons_2[1]
    Local $GUI_RESTORE_BUTTON = $Control_Buttons_2[2]
    Local $GUI_MINIMIZE_BUTTON = $Control_Buttons_2[3]
    Local $GUI_FULLSCREEN_BUTTON = $Control_Buttons_2[4]
    Local $GUI_FSRestore_BUTTON = $Control_Buttons_2[5]
    Local $Button1 = _Metro_CreateButton("Close", 250, 340, 100, 40)
    GUICtrlSetResizing($Button1, 768 + 8)
    GUISetState(@SW_SHOW)

    While 1
        _Metro_HoverCheck_Loop($Form2) ;Add hover check in loop
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON, $Button1
                _Metro_GUIDelete($Form2) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs!
                Return 0
            Case $GUI_MAXIMIZE_BUTTON
                GUISetState(@SW_MAXIMIZE)
            Case $GUI_RESTORE_BUTTON
                GUISetState(@SW_RESTORE)
            Case $GUI_MINIMIZE_BUTTON
                GUISetState(@SW_MINIMIZE)
            Case $GUI_FULLSCREEN_BUTTON, $GUI_FSRestore_BUTTON
                _Metro_FullscreenToggle($Form2, $Control_Buttons_2)
        EndSwitch
    WEnd
EndFunc   ;==>_SecondGUI

Func HostToIP($Server)
    $tdStart = TimerInit()
    $sIPAddress = TCPNameToIP($SERVER)
    If @error Then
        GUICtrlSetData($IP, "Error code: " & @error)
    Else
        GUICtrlSetData($IP, $sIPAddress)
    EndIf
    ConsoleWrite('Time for resolve: ' & TimerDiff($tdStart) & @CRLF)
EndFunc   ;==>HostToIP

 

also no problems:

Time for resolve: 37.4138078896741
Time for resolve: 4.10688525681313
Time for resolve: 3.32032425001504

the problem is TCPNameToIP, if used with a string that isn't a URL  than it's frozen using a non existing  URL it resolve fast.   So @BB_19 did good job.

Appolgise for the delay on my response. I am using it with a name rather than URL, so is there no way of getting rid of the freeze when using it with a name rather than a url?

Share this post


Link to post
Share on other sites
BrewManNH

A URL is a name. And you misread his entire point. If you send the function a URL that isn't valid, then it's going to freeze until it times out.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
cookiemonster
1 hour ago, BrewManNH said:

A URL is a name. And you misread his entire point. If you send the function a URL that isn't valid, then it's going to freeze until it times out.

Thank you for clarifying, is there anyway i can test that its valid first without having the window freeze?

If there is a function available for this whats the info page url for it for me to read up on?

Share this post


Link to post
Share on other sites
mLipok
On 30.07.2016 at 11:29 AM, cookiemonster said:

TCPNameToIP is part of #include <_sql.au3>

Try to use ADO.au3 :

https://www.autoitscript.com/forum/files/file/389-adoau3-udf/

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-09-20

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

  • Similar Content

    • rudi
      By rudi
      Hi,
      any suggestion to track down, why a script is freezing after a longer run time?
      This is a general question, I've checked the common mistakes, I've made so far (inside a loop doing fileopen() without fileclose(), runwait() for progs, that don't terminate, infinite recursive loops etc.)
       
      This script stops just after several days of running...
      Is  there a direct way to "count" the amount of MEM and handles, a autoit script is using itself, or by child processes?
       
      Regards, Rudi.
    • jasontj
      By jasontj
      Hello.  I'm working on converting another script from IE to Firefox.  I can't seem to get a handle on the field "Defendant" to fill in a last, first name on this page:
      http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal
      I also can't seem to submit the form.   I've tried the code below... stuff may be commented out that I have tested.
       
          _FFOpenUrl("http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal")    
          _FFLoadWait()
          $oTextFN = _FSObjGet("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder2_ContentPlaceHolder2_tabSearch_tabCriminal_txtCrimDefendant", "ID")
          
          _FFObj($oTextFN, "value", "Smith, John")    
          $subButton = _FFObjGet("ctl00$ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder2$ContentPlaceHolder2$btnSearch", "name")
          _FFClick($subButton)
          _FFLoadWait()
          
      ;    _FFFormSubmit()
      ;    _FFLoadWait()
       
      Any help from the experts on here would be greatly appreciated.  
       
      Jason
       
       
       
       
    • Shedunn
      By Shedunn
      I recently installed AutoIT(the most recent version) on my work computer and everytime I try to use Koda to generate code for a GUI Koda freezes....nothing can be clicked on and I have to use task manager to end the task.  It doesn't seem to matter if I open a file or if I try with a fresh design.  It also freezes if I try to change any settings within Koda

      I've tried uninstalling everything AutoIT related and reinstalling and restarting the computer.  No matter what it still does it
       
      Is there a setting somewhere that could be causing this?
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm trying to pass values to elements in a website.
      The elements are present within a table, which is again present within a table, which is inside a form.
      I tried to read the form, tables, etc., but with no results. It appears to me that the elements, tables, form, etc., were not read at all.
      The following is what I tried. Please guide me.
      ;I tried the following to read the tables into arrays #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate() _IENavigate($oIE, "---- URL HERE ----") _IELoadWait($oIE) $o_Table = _IETableGetCollection ($oIE) $i_NumTables = @extended For $i = 0 To $i_NumTables - 1 Step 1 $o_Table_Temp2 = _IETableGetCollection ($oIE, $i) $a_TableData = _IETableWriteToArray ($o_Table_Temp2) _ArrayDisplay($a_TableData) Next  
      ;I tried the following code to pass value to the field #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate() _IENavigate($oIE, "---- URL HERE ----", 0) _IELoadWait($oIE) Local $oForm = _IEFormGetObjByName($oIE, "default") Local $oField = _IEFormElementGetObjByName($oForm, "tGroup") _IEFormElementSetValue($oField, "---- VALUE HERE ----")  
      The following is the html view of the website and the highlighted field is the one that I want to pass values to. Since this is an official website, I can't share the exact url.

    • kingjacob90
      By kingjacob90
      Hi
      I am trying to send a file over TCP from a TCP client to server. If I run the server and client on the same computer the file is send fine, but if the server is on one computer on the network and the client on another the file is sent in what looks like more than one packet. In other words the server receives 4 msg from the client.
      Why is this, how do I make it send in one go, or what is a way around it?
      Side Note: TCP server has a max of 999999999
×