Jump to content

A CreateThread Problem. plz help me


Recommended Posts

This is my code. I just know a litle about createthread. Some problem with my code, i can't fix.

Please help me

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiStatusBar.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

Dim $AvatarPic
Dim $button
Dim $thread = False
Dim $loaded = False

Func FunctionThread()
    ;$nick = "thanhduyphp"
    InetGet("http://img.msg.yahoo.com/avatar.php?yids=thanhduyphp&format=gif","#.gif")
    $loaded = True
    $thread = False
    ;ConsoleWrite("~~~~~~~~~End thread" & @CRLF)
    ;$b = TimerInit()
    ;While TimerDiff($b) < 10000
    ;WEnd
    ;ConsoleWrite("############End thread" & @CRLF)
EndFunc

Func Handle()
    If FileExists("#.gif") Then FileDelete("#.gif")
    Local $handle = DllCallbackRegister("FunctionThread","int","")
    DllCall("kernel32.dll","hwnd","CreateThread","ptr",0,"int",0,"ptr",DllCallbackGetPtr($handle),"ptr",0,"dword",0,"ptr",0)
    ConsoleWrite("----------> Start thread" & @CRLF)
EndFunc

GUICreate("Gui Test",200,300)
$button = GUICtrlCreateButton("Get Avarta",15,15)
$AvatarPic = GUICtrlCreatePic("", 16, 88, 96, 96, BitOR($SS_NOPREFIX,$SS_NOTIFY,$SS_RIGHTJUST,$WS_GROUP,$WS_TABSTOP,$WS_BORDER))
GUISetState()

While 1
    Local $msg = GUIGetMsg()
    IF $msg == $button and Not $thread Then
        $thread = True
        Handle()
    EndIf

    If $msg == $GUI_EVENT_CLOSE Then Exit

    If $loaded Then
        $loaded = False
        GUICtrlSetImage( $AvatarPic , "#.gif")
        ;FileDelete("#.gif")
    EndIf
WEnd
Link to comment
Share on other sites

What exactly you want to do?

It still have a big error. Can you fix it for me.

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\SONY VAIO\Documents\AutoIt\Test2.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams    
+>16:42:28 Starting AutoIt3Wrapper v.2.0.0.1    Environment(Language:0409  Keyboard:00000409  OS:WIN_VISTA/  CPU:X64 OS:X86)
>Running AU3Check (1.54.14.0)  from:C:\Program Files\AutoIt3
+>16:42:29 AU3Check ended.rc:0
>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Users\SONY VAIO\Documents\AutoIt\Test2.au3"    
----------> Start thread
!>16:42:39 AutoIT3.exe ended.rc:-1073741819
+>16:42:40 AutoIt3Wrapper Finished
>Exit code: -1073741819    Time: 11.501
Link to comment
Share on other sites

For me work fine on WinXP Professional SP3. I saw that you use Win Vista, maybe this is the problem. Please tell me what you what to do and maybe I can help you? You want just to get the yahoo avatar and put in your GUI?

When the words fail... music speaks.

Link to comment
Share on other sites

AutoIt is not thread-safe so pointing new threads to autoit callbacks will sooner or later make code collide and crash pretty hard.

You'll have to rethink your logic or implement the thread in a different language.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Actually, all you're doing is making an InetGet call which can be done async. Just look at the helpfile for InetGet.

And if you install the Beta (>= 3.3.1.0), you can have multiple downloads with the "background" parameter :)
Link to comment
Share on other sites

My progam is get avatar and check that yahoo's invisible or offline. But it still take the long time have a response from sever. Thus, i want to create thread to do that thing. The program don't need to wait response from server. it can do some thing else.

This is my soft.

http://www.mediafire.com/?eicyomzjmtm

Link to comment
Share on other sites

My progam is get avatar and check that yahoo's invisible or offline. But it still take the long time have a response from sever. Thus, i want to create thread to do that thing. The program don't need to wait response from server. it can do some thing else.

This is my soft.

http://www.mediafire.com/?eicyomzjmtm

I repeat, you can create a separate process for this and use WM_COPYDATA for communicate between processes. Multithreading will not work in AutoIt. He does not designed for this.

Edited by Yashied
Link to comment
Share on other sites

I repeat, you can create a separate process for this and use WM_COPYDATA for communicate between processes. Multithreading will not work in AutoIt. He does not designed for this.

http://msdn.microsoft.com/en-us/library/ms682453(VS.85).aspx

CreateThread Function

Creates a thread to execute within the virtual address space of the calling process.

To create a thread that runs in the virtual address space of another process, use the CreateRemoteThread function.

But in Autoit that is not possible except by using

Assembly language Through the Autoit language

Such an example in this topic

Execute in a different thread

http://www.autoitscript.com/forum/index....&st=0&p=686626&fromsearch=1&#entry686626

in Autoit Function does not work

properly as this example

#include <GUIConstantsEx.au3>
GUICreate("CreateThread") 
$Button = GUICtrlCreateButton("CreateThread", 10, 30, 150)
 GUISetState()      

$i1 = 0
While 1
$i1 += 1
ToolTip("LOOP1 = " & $i1,200, 100)
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button
$handle = DLLCallbackRegister ("ThreadProc", "int", "ptr")     
$Return = DllCall("Kernel32.dll","hwnd","CreateThread","ptr",0,"int",0,"ptr",DllCallbackGetPtr($handle),"ptr",0,"int",0,"ptr*",0)
$handle = $Return[0]
$lpThreadId = $Return[6]
EndSelect
WEnd




Func ThreadProc($lpParameter)
$i2 = 0
While 1
if GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
$i2 += 1
ToolTip("LOOP2 = " & $i2,300, 100)
WEnd
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...