Jump to content

True AutoIt multi-threading!


NHD
 Share

Recommended Posts

  • 2 weeks later...
  • 3 months later...

What if you have a rather large compiled exe? it looks like you would be dealing with AutoIt Exe*N threads. What if you were to modify N_GetBinaryModule so that it detects the script resource and omits it?

What is what? What is what.

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

This is great! I love it!

I hope that I'm not asking a newb question ... is there a way to exit a thread?

For instance:

1st thread: I start a thread with a GUI. Then I spawn a 2nd thread from here ...

2nd thread: This thread has a TCPRecv in a loop which is always listening to a networked device. The messages received from this device then go into a shared global queue. The GUI then updates itself based on the messages found in the queue.

3rd thread: Then I want to start a thread from the 2nd thread that will process the messages received from the network (shortens them and converts them from binary). I want to be able to exit that third thread. 

Or does it happen that way and I'm just looking at this all wrong?

The following code does not demonstrate my intentions. Just sharing it for completeness. (Also, it  doesn't actually implement a real queue data structure at the moment.)

#AutoIt3Wrapper_Version=B
#Autoit3Wrapper_Testing=y
#autoit3Wrapper_jump_to_first_error=y
#AutoIt3Wrapper_Run_AU3Check=n
#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 4 -w 5 -w 6 -w 7 -d

#NoTrayIcon

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

#include "N.au3"

OnAutoItExitRegister(OnAutoItExit)

Global $queue = NGlobal()

NMain("Main")

Func Main()
    GUICreate("EISCP", 520, 350)

    Local Const $edit = GUICtrlCreateEdit('', 10, 10, 500, 330, $ES_AUTOVSCROLL + $WS_VSCROLL)

    GUISetState(@SW_SHOWNORMAL)

    NRun("Recv")

    Do
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch

        GUICtrlSetData($edit, $queue.Command, 1)

        Sleep(100)
    Until False
EndFunc

Func Recv()
    TCPStartup()

    Local Const $sIPAddress = "192.168.0.209"

    Local Const $iPort = 60128

    Local Const $ConnectedSocket = TCPConnect($sIPAddress, $iPort)

    Local $command

    Do
        $command = TCPRecv($ConnectedSocket, 2048)

        If $command Then
            $queue.Command = ExtractCommand($command)
        EndIf

        Sleep(50)
    Until False
EndFunc

Func ExtractCommand($command)
    $command = BinaryMid($command, 5) ; lop off "ISCP"

    $command = BinaryMid($command, 15)

    $command = BinaryMid($command, 1, BinaryLen($command) - 3)

    Return String(BinaryToString($command))
EndFunc

Func OnAutoItExit()
    TCPShutdown()
EndFunc

 

Link to comment
Share on other sites

  • Moderators

https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminatethread

TerminateThread, but I read somewhere that GetCurrentThreadId from Kernel32 dll was deprecated, so I can't see "TerminateThread" from the processthreadsapi api being to safe tbh.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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