Multi-thread - AutoIt Example Scripts
Có thể bạn quan tâm
- All Activity
- Home
- AutoIt v3
- AutoIt Example Scripts
- Multi-thread AutoIt
- multi-thread
By FredAI December 18, 2012 in AutoIt Example Scripts
Share https://www.autoitscript.com/forum/topic/146794-multi-thread-autoit/ More sharing options... Followers 0- Prev
- 1
- 2
- Next
- Page 1 of 2
Recommended Posts
FredAI
Posted December 18, 2012FredAI
- Active Members
-
- 82
Hello.
This example shows how to create ad manage several threads from a unique autoIt script with the help of an external dll.
I read many people saying it's not possible to have more than one thread in AutoIt. It's not true. We can do anything if we have a helper DLL to do the things we can't do within the autoIt script.
The example also shows how we can make the DLL and the AutoIt code comunicate between themselves.
The zip contains the full code (AutoIt and the C++ project). The script and the DLL are placed in the Release folder.
Feel free to modify and use in any project.
The VC++ project was created with Visual C++ Express 2010. It's free but requires an email registration.
I intend to post a tutorial on how to use your own helper DLL to improve performance and do the things you can't do with AutoIt.
I'ts cool having the AutoIt coding facilities and the power of a general language mixed altogether.
Enjoy!
MT AutoIt.zip
Edited December 19, 2012 by FredAI- Chance
- 1
My UDFs: SetAcl permissions | System restore
Examples: File version info editor | GetIp() improved
Programs: UVK - Ultra virus killer | ExeFixer | Recent file seeker | SHIcon | Quick_Any2Ico
JScript
Posted December 18, 2012JScript
- Active Members
-
- 1.2k
- 2
- I'm back ... I miss, why not!
Very nice, but only MsgBox()?
Give us another example, please.
JS
Edited December 18, 2012 by JScripthttp://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Somewhere Out ThereJames Ingram
Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!
JohnOne
Posted December 18, 2012JohnOne
- Active Members
-
- 17.4k
- 119
- Number #1
Here is a couple of funcs, if you could demonstrate them working concurrently it would be a great help.
_Func1() _Func2() Func _Func1() Sleep(10000) EndFunc ;==>_Func1 Func _Func2() $i = 1 While $i < 11 ConsoleWrite("_Func2" & @LF) Sleep(1000) $i += 1 WEnd EndFunc ;==>_Func1AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify
Monkey's are, like, natures humans.
FredAI
Posted December 18, 2012FredAI
- Active Members
-
- 82
- Author
Ok, here's a quick explanation of what happens when you run the script:
First we load kernel32.dll and our MT_AutoIt.dll.
Global Const $Kernel32Dll = DllOpen('Kernel32.dll') Global Const $MT_AutoItDLL = DllOpen('MT_AutoIt.dll')Then we create a small GUI using native AutoIt code and display it.
Local $MainGUI = GUICreate('Main thread GUI',400,300), $msg GUISetState()Then we create three small structures that will hold the text to pass to the new threads' functions, holded by our dll.
Here's where lies the core of the threading method. While these structs are very simple, they coul have anything we wanted. Tons of info we could pass to the new threads, in order to make them perform more complicated tasks than just displaying a message box, of course.
The first parameter of the _AutoItThreadCreate function, $index is intended to tell the dll which thread calback to use, allowing to create four different functions to perform four different tasks.
You will note that all message boxes are displayed simultaneously, an probably the one thea corresponds to the first thread is not the first one to be displayed. This is because when the CreateThread function is called by the DLL, it returns immediately, even before the thread is started.
in fact we only need one index to have the three message boxes in different threads. The message box that displays "This is thread 3 running in the same function as the thread 1" uses the same calback as the one that displays "This is thread 1".
That means we can create as many threads as we want using always the same calback.
I guess I have to make a better example showing the different calbacks perform different tasks.
My UDFs: SetAcl permissions | System restore
Examples: File version info editor | GetIp() improved
Programs: UVK - Ultra virus killer | ExeFixer | Recent file seeker | SHIcon | Quick_Any2Ico
JScript
Posted December 18, 2012JScript
- Active Members
-
- 1.2k
- 2
- I'm back ... I miss, why not!
Did not answer the question of JohnOne and neither gave me more examples...
JS
http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Somewhere Out ThereJames Ingram
Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!
Chance
Posted December 18, 2012Chance
- Active Members
-
- 187
- 1
Neat.
Can you show us how to do a callback?
Like say, the message box pops up, and then you click a button and it makes a call back to an autoit function and tells you the button you pressed?
I made some modifications so I could compile with MinGW, it's working nicely.
Here is a couple of funcs, if you could demonstrate them working concurrently it would be a great help.
I know you saw the DLL source code, come on, you should know what he was talking about.
He's just trying to introduce people to creating dlls that can spawn a thread and do simple operations, not run another instance of the script interpreter, maybe you should have said he needs to point that out?
Edited December 18, 2012 by DeputyDerpFredAI
Posted December 18, 2012FredAI
- Active Members
-
- 82
- Author
Easy, guys, I'm working in a better example.
My UDFs: SetAcl permissions | System restore
Examples: File version info editor | GetIp() improved
Programs: UVK - Ultra virus killer | ExeFixer | Recent file seeker | SHIcon | Quick_Any2Ico
JohnOne
Posted December 18, 2012JohnOne
- Active Members
-
- 17.4k
- 119
- Number #1
I know you saw the DLL source code, come on, you should know what he was talking about.
Well at first glance, it looks like any threaded work must be coded in the dll file
and AutoIt will still just work in one thread procedurally.
I'm hoping to be dead wrong though.
AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify
Monkey's are, like, natures humans.
JScript
Posted December 18, 2012JScript
- Active Members
-
- 1.2k
- 2
- I'm back ... I miss, why not!
Let's wait for another example because until now is quite similar the following UDF:
JS
http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Somewhere Out ThereJames Ingram
Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!
Digisoul
Posted December 18, 2012Digisoul
- Active Members
-
- 340
where is multi threading ?
Change the topic title please.
73 108 111 118 101 65 117 116 111 105 116
FredAI
Posted December 18, 2012FredAI
- Active Members
-
- 82
- Author
where is multi threading ?
Change the topic title please.
It's comments like this one that keep me away from the forums.
Did you even take a look at the code?
Didn't you see that the DLL is creating each message box in a different thread by calling CreateThread?
Didn't you see the message boxes being closed each time TerminateThread is called?
Isn't that multi-threading?
Work first. Comment later.
My UDFs: SetAcl permissions | System restore
Examples: File version info editor | GetIp() improved
Programs: UVK - Ultra virus killer | ExeFixer | Recent file seeker | SHIcon | Quick_Any2Ico
JohnOne
Posted December 18, 2012JohnOne
- Active Members
-
- 17.4k
- 119
- Number #1
Just a flippant comment that FredAl.
MultiThreading, has in my time here, been quite the turbulent subject.
People read the scoop headline and hope for multiple threads in their own
AutoIt code.
I was hoping for the same myself, don't let it dishearten you.
AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify
Monkey's are, like, natures humans.
Andreik
Posted December 19, 2012Andreik
- Active Members
-
- 4k
- 108
- Joker
It's useless if you have to write all threads in C, inside of this DLL. In this case it would be better to write entire application in C.
FredAI
Posted December 19, 2012FredAI
- Active Members
-
- 82
- Author
Ok, new example updated. Download in the first post, please.
It's useless if you have to write all threads in C, inside of this DLL. In this case it would be better to write entire application in C.
Well, you don't have to write all the threads, each TreadProc function can run as many threads as you want.
And since you can pass data to the function, it can perform several different tasks depending on the data passed.
The new example shows exactly that. The left window shows the upper part of the desktop scroling in its client area, while the right window shows the bottom. But they both run in the same function's body, in different threads.
Anyway, the point is that you can use the dll to help you not only to create threads, but also to perform other tasks you can't with AutoIt code.
For instance how do you access Windows api macros such as MAKEINTRESOURCE from AutoIt? How about the C++ classes defined in the Windows headers?
Wee, now you can acces them all. Just create a new exportable function in the Dll that calls the macro or the class and returns the desired value to your AutoIt code.
Honestly, I thought this example would be received with more enthusiasm.
I use a helper dll in one of my AutoIt aps, to help with the drawing and big loops. I had a speed improvement of 1000%. Most of the functions that took long time to return, now they return ten times faster.
My UDFs: SetAcl permissions | System restore
Examples: File version info editor | GetIp() improved
Programs: UVK - Ultra virus killer | ExeFixer | Recent file seeker | SHIcon | Quick_Any2Ico
JScript
Posted December 19, 2012JScript
- Active Members
-
- 1.2k
- 2
- I'm back ... I miss, why not!
@FredAI
I'm sorry to tell you that your example stays the same to the following UDF:
If you do a search on the forum you will find several topics with the same attempt to multi-thread, I do not say that you'll have to give up but it has been tried several times and no one came to desired!
Note: This using the same dll as the dll you have not posted the new example!
JS
Edited December 19, 2012 by JScripthttp://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Somewhere Out ThereJames Ingram
Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!
FredAI
Posted December 19, 2012FredAI
- Active Members
-
- 82
- Author
Shoot! I had cleaned the project and forgot to put the dll back again.
It's now updated. Thanks for the warning.
My UDFs: SetAcl permissions | System restore
Examples: File version info editor | GetIp() improved
Programs: UVK - Ultra virus killer | ExeFixer | Recent file seeker | SHIcon | Quick_Any2Ico
FredAI
Posted December 19, 2012FredAI
- Active Members
-
- 82
- Author
Just a small note: On Windows x64 you must either compile the script x86 or run it from scite, because the dll is compliled x86.
My UDFs: SetAcl permissions | System restore
Examples: File version info editor | GetIp() improved
Programs: UVK - Ultra virus killer | ExeFixer | Recent file seeker | SHIcon | Quick_Any2Ico
davidkim
Posted December 20, 2012davidkim
- Active Members
-
- 107
DWORD WINAPI _ThreadProc1(LPVOID param)
{
PWSTR wstr = (PWSTR)param;
MessageBox(0,wstr,L"Thread message",MB_OK);
return 0;
} // End of _ThreadProc1
DWORD WINAPI _ThreadProc2(LPVOID param)
{
PWSTR wstr = (PWSTR)param;
MessageBox(0,wstr,L"Thread message",MB_OK);
return 0;
} // End of _ThreadProc1
DWORD WINAPI _ThreadProc3(LPVOID param)
{
PThreadProc3Data thpd = (PThreadProc3Data) param;
HWND desktopHwnd = GetDesktopWindow();
HDC desktopDC = GetDC(desktopHwnd);
int desktopwidth = GetDeviceCaps(desktopDC,HORZRES);
HDC hdcpic = GetDC(thpd->hwnd);
for (int i=0;i<desktopwidth;i++)
{
BitBlt(hdcpic, 0, 0, 240,180, desktopDC, i, thpd->top, SRCCOPY);
//picgr.DrawImage(&desktopBmp,i,thpd->top,240,180);
SleepEx(20,true);
if (i == desktopwidth-240-1) i = 0;
}
return 0;
} // End of _ThreadProc1
DWORD WINAPI _ThreadProc4(LPVOID param)
{
PWSTR wstr = (PWSTR)param;
MessageBox(0,wstr,L"Thread message",MB_OK);
return 0;
} // End of _ThreadProc1
the function making autoit source can?
use the new function is edit MT_AutoIt.cpp only?
make autoit source in function can?
I interest am many quite in AutoitScript.From that is [http://cafe.naver.com/autoitscript[/color]] Korea of cafe(blog) to be operating, [size="2"][color="#ff00ff"]English cannot well[/size].Many help it requests.To read, it stands it thanks.
Chance
Posted December 20, 2012Chance
- Active Members
-
- 187
- 1
the function making autoit source can?
use the new function is edit MT_AutoIt.cpp only?
make autoit source in function can?
It does not work like that.
davidkim
Posted December 20, 2012davidkim
- Active Members
-
- 107
It does not work like that.
ah....
thanks DeputyDerp
I interest am many quite in AutoitScript.From that is [http://cafe.naver.com/autoitscript[/color]] Korea of cafe(blog) to be operating, [size="2"][color="#ff00ff"]English cannot well[/size].Many help it requests.To read, it stands it thanks.
- Prev
- 1
- 2
- Next
- Page 1 of 2
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 accountSign in
Already have an account? Sign in here.
Sign In Now Share https://www.autoitscript.com/forum/topic/146794-multi-thread-autoit/ More sharing options... Followers 0 Go to topic listing-
Recently Browsing 0 members
- No registered users viewing this page.
- All Activity
- Home
- AutoIt v3
- AutoIt Example Scripts
- Multi-thread AutoIt
- Existing user? Sign In
- Sign Up
-
Browse
- Back
- Forums
- Downloads
- Events
- Forum Rules
- Wiki
-
AutoIt Resources
- Back
-
Release
- Back
- Installer
- Help file
- Editor
-
Beta
- Back
- Installer
- Help file
- Editor
- Git
- FAQ
- Create New...
Từ khóa » đa Luồng Autoit
-
Hướng Dẫn - [Advanced] Callback & Phương Pháp Đa Luồng Trong ...
-
Authread Autoit (Multi Thread) | Đa Luồng Autoit | Tool By Autoit
-
Help - Làm Sao để Autoit Chạy Multi Thread | Kiếm Tiền Online
-
Autoit Là Gì? Tìm Hiểu Lý Do Mà Ngôn Ngữ Lập Trình Autoit Bị Ghét Bỏ
-
AutoIT Ngôn Ngữ Lập Trình Bị Ghét Bỏ? - Viblo
-
Tại Sao AutoIt Luôn Bị “ghét”? - Juno_okyo
-
AutoIT Việt Group | Làm Thế Nào để Lấy được Nội Dung Trong Thẻ ...
-
AutoIT Việt Group | Facebook
-
Multi Threading (đa Luồng) Trong C# | How Kteam
-
Hiệu ứng Chữ "rực Lửa" Cho GUI - Autoit - Huỳnh Phúc Huy 's Blog
-
Share Tài Liệu Học Autoit Trong 5 Phút Của Boss Viết 2 Năm Trước Link
-
Tại Sao Autoit Là Gì ? Giới Thiệu Về Ngôn Ngữ Lập Trình Autoit
-
Ngôn Ngữ Autoit Là Gì?