Problem With invokeAsynchronous

I am currently trying to create a script that opens an image that the user selects. It will then take this image and attach it to an email that is sent out. I’ve got it so that the image loads and the email is sent out. However, whenever it does this it locks up the GUI. I’ve even added in invokeAsynchronous to the script but it will still lock up the GUI and I am confused as to why. The CPU usage never goes above 30% when this script is running (generally around 10%) and I can use other programs while it is running with no problem. Below is my code and I have it set to run when a button is clicked. Any help would be greatly appreciated.

-Will

if system.tag.getTagValue("[System]Client/User/Username") in ["user1", "user2"]: path = system.file.openFile() if path != None: def longProcess(path = path): import system bytes = system.file.readFileAsBytes(path) def afterLongProcess(bytes = bytes): import system smtp = "smtp.gmail.com:587:tls" fromAddr = "sender@address.com" subject = "Subject" body = "Body" recipients = ["email@address.com"] fileData = bytes fileName = "Image_1.png" password = "password" system.net.sendEmail(smtp, fromAddr, subject, body, 0, recipients, [fileName], [fileData], 60000, fromAddr, password) system.gui.messageBox("Email was successfully sent.", "Email Complete") system.util.invokeLater(afterLongProcess) system.util.invokeAsynchronous(longProcess) else: system.gui.warningBox("No Image Selected", "Warning")

Everything in your afterLongProcess() call runs in the UI thread - have you checked to see if system.net.sendEmail() is blocking for any amount of time?

Kevin - Never thought of that. Always assumed since the code was inside the asynchronous function that it would run the sendEmail as part of the asynchronous thread. Would there be any problem with taking the sendEmail part out of the invokeLater and running it in the asychronous thread?

That’s probably the right approach.

As it is, you’re explicitly asking afterLongProcess() to be run on the UI thread by calling system.util.invokeLater().

Thanks a bunch Kevin! That did the trick.