Sign in to follow this  
Followers 0
Mechaflash

Run 2 functions at the same time

6 posts in this topic

Is there a way to call 2 functions to run at the same time?

It works overnight in thunderbird to pull some attachments, and after the attachments get extracted and thunderbird is closed, I want to call function 1 which prints them and function 2 which performs my nightly backup of my thunderbird profile.

I can't call them one after the other because function 1 stays active until all files are done printing and out of the print queue, which can sometimes take until the next morning because of paper jams, print carriage full, etc.

I know the easy way is to just isolate function 2 into its own program and run it that way, but I was curious if this was possible or not.


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites



Hello mechaflash213,

Unfortunately, AutoIt is not a multi-threaded language. However, If Func1() can be momentarily paused while Func2() performs the necessary step, then I would suggest AdlibRegister().

AdlibRegister() is as closed to multi-threading as you can get with AutoIt. Make your check routine as small as possible to call Func2() when conditions have been met. In the second parameter of AdlibRegister() you can adjust how often it will run your check routine in milleseconds, default is 250 ms.

P.S. Creating another application to check is another way, however, make sure that it's performance will not clash with the first applications performance.

Good Luck & Happy Coding!

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can also communicate between two scripts using something like This is not running two functions in the same script, but it might offer an alternative approach you hadn't thought of.

Edited by czardas

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You can also communicate between two scripts using something like This is not running two functions in the same script, but it might offer an alternative approach you hadn't thought of.

That actually gave me a thought... beginning of the script I'll add a function to check my process list and see if two instances of this program is running. If not, then continue with the norm and do a run() again on this app when I need func2(). Since I now have two processes with the same name, my check will return true on my second execution, and run my func2() instead and exit afterwards.

(I know it's basically the same as running 2 EXEs but I at least don't have to have two separate EXEs to do it.)

Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Rather than monitoring processes, it would be simpler to just test CmdLine() and if the script is launched with no parameter, run it in "Mode 1" which would call the script again but with some parameter which would cause it to run in "Mode 2"

Share this post


Link to post
Share on other sites

Why whould you do it the hard way ? Just compile 3 scripts .

1. For Printing

2. For Profile Backuo

3. For ShellExecuting script 1 and script 2.

That way you will have both scripts running at the same time.

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  
Followers 0