Jump to content
IAMK

Using multithreading for polling?

Recommended Posts

IAMK

I was wondering if it would be a good or bad idea to implement multithreading purely for the sake of polling?

E.g.
Thread1: Run script as normal.
Thread2: Poll every 5 seconds for certain conditions, e.g. check processes opened, actions to execute.

Currently, the way I have my scripts is messy. I have the same condition check functions called inside all my while loops to prevent infinite looping.

Also, it would be nice to have 1 thread pause the other thread. Is that possible?
E.g. If Thread2 finds that process1 is closed, it will pause Thread1 until process1 is opened again.

Share this post


Link to post
Share on other sites
RTFC
Posted (edited)

You appear to be confusing processes and threads, i.e., multi-processing (easily done in AutoIt) versus multi-threading (not; see countless earlier discussions on AutoIt being single-threaded). Pausing and resuming processes is possible, and discussed in various forum topics (for example here and here). It is, incidentally (geek alert!), also possible in AutoIt to suspend/resume individual threads of another (multi-threaded) process (e.g., some dlls), but since AutoIt scripts are themselves single-threaded, that does not apply in this context (plus: here be dragons...:evil:). The two previous suggestions by Jos and Bert should work out fine for quick and simple tasks. If, however, multiple tasks are time-critical and must run alongside each other, I'd suggest writing two separate scripts (one launching and controlling the other), and having them communicate with IPC (inter-process communication, again, plenty of examples on the forum on that subject).

BTW attempting to force AutoIt to run multi-threaded has been known to open interdimensional portals, releasing hell-spawn and brain-eating demons... I'd suggest you keep that door closed.;)

Edited by RTFC

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

×