Jump to content
Sign in to follow this  

Execute function without wait.

Recommended Posts


Hey, I'm writing a light control app, and I'm trying to work out the best way to run a function, such as a fade, which will happen over a period of time, without affecting the GUI of my application.

I suppose (I could be wrong) but I am asking for multi-threading capabilities, or forking or whatever. I'd be interested to know whether it's possible, and if someone could give me an example of executing a function with parameters, which allows the script to continue without waiting for the function to complete it's execution.

Hope that's not too jumbled up! Cheers!

Share this post

Link to post
Share on other sites

Interestingly enough, I found what I was looking for. It's not multi-threading as such, but it does exactly what I need it to do.

#include <GuiConstants.au3>

$Gui = GuiCreate("Custom _AdlibEnable Demo", 300, 130)

$Left = -200
$Label = GUICtrlCreateLabel("Drag the window, i am just a runing text ;) ", $Left, 100)

$RunCheckBox = GUICtrlCreateCheckbox("Run text", 20, 40)


While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
        Case $RunCheckBox
            If GUICtrlRead($RunCheckBox) = 1 Then
                _AdlibEnable("_TimerFunc", 30, $Gui)

Func _AdlibEnable($sFunction, $iTime=250, $hWnd=0)
    Local Const $WM_TIMER = 0x0113
    If Not IsHWnd($hWnd) Then $hWnd = GUICreate("hCallBack_AdlibEnable")
    GUIRegisterMsg($WM_TIMER, $sFunction)
    Local $aRet = DllCall("User32.dll", "int", "SetTimer", "hwnd", $hWnd, "int", 50, "int", $iTime, "int", 0)
    Return $hWnd

Func _AdlibDisable($hWnd=0)
    Local Const $WM_TIMER = 0x0113
    GUIRegisterMsg($WM_TIMER, "")
    Local $aRet = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int*", 50)
    Return Number(IsArray($aRet) And $aRet[0])

Func _TimerFunc()
    $Left += 2
    If $Left >= 300 Then $Left = -200
    ControlMove($Gui, "", $Label, $Left, 100)

(Example courtesy of MrCreatoR, many thanks!)

Share this post

Link to post
Share on other sites

Multi-threading is hugely overrated. I have almost never used it. Almost any problem can be solved without it.

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

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

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.