Jump to content

Example how to read webpage to a variable in background without temp file


Guest
 Share

Recommended Posts

Hello,

Today I tried to find a way how to read a page to a variable in background without freezing the script and without using temp file during the process.
 
 

I managed to do it!

; Example how to read webpage to a variable in background without freezing the script
; Using fixed _ThreadStart() function


Global $InetRead = -1
;MsgBox(0,"","")
_ThreadStart("_Thread1")

While 1
    ToolTip("Just to show that the script is not frozen")
    If $InetRead <> -1 Then
        ConsoleWrite($InetRead&@CRLF)
        $InetRead = -1
    EndIf
    Sleep(10)
WEnd



Func _Thread1($vDummy)
    $InetRead = BinaryToString(InetRead("http://www.autoitscript.com/site/"))
EndFunc   ;==>_Thread1




; #FUNCTION# ====================================================================================================================
; Name ..........: _ThreadStart
; Description ...: 
; Syntax ........: _ThreadStart($sFunctionName)
; Parameters ....: $sFunctionName       - A string value.
; Return values .: None
; Author ........: Your Name
; Modified ......: gil900 - fixed what caused the script to crash
; Remarks .......: 
; Related .......: 
; Link ..........: Originally posted here: http://www.autoitscript.com/forum/topic/124393-multithreading-example/
; Example .......: No
; ===============================================================================================================================
Func _ThreadStart($sFunctionName)
    Local $h1, $h2, $h3 = DllStructCreate("hwnd[1]"), $h4 = DllStructGetPtr($h3)

    $h1 = DllCallbackRegister($sFunctionName, "int", "int")
    $h2 = DllStructCreate("int")
    $h3 = DllCall("Kernel32.dll", "hwnd", "CreateThread", "ptr", 0, _
            "int", 0, _
            "ptr", DllCallbackGetPtr($h1), _
            "int", 0, _
            "int", 0, _
            "ptr", DllStructGetPtr($h2))
    DllStructSetData($h3, 1, $h3[0], 1)
;~  DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", DllStructGetData($h3, 1, 1)) ; Disabled - This line caused the script to crash
EndFunc   ;==>_ThreadStart

I hope you found it useful!

 

EDIT:

seems that sometimes it still crash :(

But it works well most of the time.

So maybe I gave a good start for someone else to make more stable code.

Edited by Guest
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...