Jump to content

UDF : Multi-threading made easy


Nine
 Share

Recommended Posts

I need from from time to time to run small processes to perform task that would otherwise clog the main process.  Yes, there is a number of other UDF that could have done it very well, but I felt they were an over-kill for what I wanted.

Don't throw me stones, I know it's not really multi-threading, but it is as close as I could get with simple AutoIt.  If someone wonders why I called it PMT, the P stands for Pretending.

And I'm also not pretending it is an elaborate UDF.  Just small and simple to use...

Version 2024-03-24

* corrected bug when 8 parameters (max) is passed to the function

Example :

#AutoIt3Wrapper_Res_SaveSource=y

#include "PMT-UDF.AU3"
#include <Constants.au3>

_PMT_Init()

Local $hProc1 = _PMT_Start("Test1", Default, "Test 1")
_PMT_Start("Test2")
_PMT_Start("Test3", 5)
Local $sResponse
While Sleep(50)
  $sResponse = _PMT_GetResponse($hProc1)
  If @error Then Exit MsgBox($MB_OK, "Error", "Process has dropped")
  If $sResponse <> "" Then
    MsgBox($MB_OK, "Success", $sResponse & @CRLF)
    ExitLoop
  EndIf
WEnd

Func Test1($sTitle, $sMessage)
  Local $iResp = MsgBox($MB_OK, $sTitle, $sMessage)
  Return "Done with value " & $iResp
EndFunc

Func Test2()
  MsgBox($MB_OK, "2", "Test 2")
EndFunc

Func Test3($iTimeout)
  MsgBox($MB_OK, "3", "Test 3", $iTimeout)
EndFunc

You can pass up to 8 parameters to _PMT_Start.  It is up to you to manage the right number.

You cannot pass structures, maps or arrays as parameter (only bool, ptr, hWnd, int, float, string, and the keyword Default).  You could use my WCD-IPC if need be to exchange large amount of data.

If you want to run it compiled, you need to have add #AutoIt3Wrapper_Res_SaveSource=y at the start of your script.  In the case you decide to compile your script, _PMT_Init allows you to identity where AutoIt3 is located (in the situation where AutoIt is not installed in the usual directory) to get the right includes in your "threads".

Let me know if you have any question, or suggestion, I will be glad to hear them.

Enjoy. 

PMT-UDF.au3

Edited by Nine
Link to comment
Share on other sites

How does it feel when you have written more than 39,000 program codes and because of an unwanted change, your compiled program is decompiled by a thief?

Thanks to my dear friend Nine for sharing his nice code

I compile my program with the following parameters
The presence of your line code made me worry that a copy of the program source should be saved in the compiled version

Edited by Parsix
Link to comment
Share on other sites

@Parsix  Please edit your post and make it normal font.  All programs can be decompiled, even more easily if it is a scripting language.  The way this UDF is made, it is needed to include the original code inside the .exe.  If you are afraid that your code get stolen, there is nothing much you can do against someone with bad intents.

Link to comment
Share on other sites

51 minutes ago, Nine said:

@Parsix  Please edit your post and make it normal font.  All programs can be decompiled, even more easily if it is a scripting language.  The way this UDF is made, it is needed to include the original code inside the .exe.  If you are afraid that your code get stolen, there is nothing much you can do against someone with bad intents.

It is the intellectual preoccupation of every programmer

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