Xichael

Singleton Wait?

7 posts in this topic

I have a script that I run via an Explorer context menu entry (created in Regedit) which is being passed a selection of file paths. It works something like this:

FileWrite("File.txt", $CmdLine[1] & @CRLF)
_Singleton(@ScriptName)
Run("Notepad.exe " & "File.txt")

With this, a number of instances of the script run (based on the number of files selected in Explorer) until they reach _Singelton, at which point each instance quits until only the first instance remains to run the remaining code (at least in my understanding of how singleton works).

Problem is, sometimes that first instance makes it to the Run command before the other instances are done writing to the file, giving me an incomplete list of the values being passed from Explorer.

Other than putting a Sleep before Run, or having to compile the script and do some kind of "While more than one ProcessExists" loop, how can I make sure that Run happens only after all other instances have finished writing to the file? In other words, something like a "SingletonWait" function – a way for the first instance to pause until all other instances have closed.

Share this post


Link to post
Share on other sites



Do all instances need to share the file? Or could you create a unique file for each instance like:

FileWrite("File_" & @AutoItPID & ".txt", $CmdLine[1] & @CRLF)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

That's actually something I've experimented with, and after which doing a For...FileReadLine...FileWrite to get the results back into one file, but the result was the same. Sometimes it would manage to collect all the lines before reaching Run, sometimes not.

Edited by Xichael

Share this post


Link to post
Share on other sites
5 hours ago, Xichael said:

... how can I make sure that Run happens only after all other instances have finished writing to the file?

How do you know how many instances have/will be started?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It depends on the number of files selected in Explorer. It's being launched from the context menu.

Share this post


Link to post
Share on other sites

I see. But how should the first script know how many instances will be started so it can tell when all instances have written to the file and processing can continue?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

EDIT - What water said :D, plus ......

_Singleton has parameters, so you should code something based on that.

Check out my Example, which has other links in it too.

 

 

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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