Nick Mudge Ignition Software Consulting & Development

The Vision Module, which is installed in Ignition by default, enables people to create Java-based graphical user interfaces. The underlying Java library that Vision Module GUIs are created upon is Java Swing. Java Swing is a standard graphics library that ships with Java, so you can learn all about it on the Internet and in books.

Because Vision Module-based GUIs are built on top of Java Swing, they follow the rules of Java Swing.

A primary rule of Java Swing is that the user interface is single threaded.

This single thread is called the Event Dispatch Thread or EDT. Code that touches the user interface is supposed to execute in the EDT. This paradigm eliminates numerous multithreading problems and hassles by not having multiple threads touch the GUI.

All the component event handling code in Ignition and the extension functions on components run in the EDT by default so you don't have to do anything special to make your code execute in the EDT. It is the default.

But if this was the end of the story there would be a big problem in Ignition GUI development. The GUI should be and needs to be very very fast - always. A slow, unresponsive GUI (even if it is just a little slow) means that a programmer didn't program it to be fast.

Some code is a little slower than very very fast, and some code is a lot slower, and there is no way around it. Database queries, requests over the network, computations over large sets of data, all these things can take awhile.

If long running code executes in the EDT then the GUI will freeze and appear slow. This is obvious since the EDT can't do anything else until it is done doing what it is currently doing. So if the EDT needs to make a database query (or other such thing) over a potentially slow network the GUI will freeze while this happens and the user will feel like the application is slow or broken.

Executing code that directly affects the GUI such as setting values on component properties, moving components, changing the display of components in some way, and configuring components is usually very fast. It is actually the non-GUI code that is most often slow, like getting data over a network and processing lots of data.

So the question is, How do you make a very fast GUI always when you have code that takes awhile to execute? The answer is to separate the slow (data processing or data retrieval) code from the fast GUI manipulation code. Put the slow code in a background thread. When the slow code completes execution have the background thread pass the data results to code in the EDT that configures and updates the GUI with that data.

Ignition provides the system.util.invokeAsynchronous(func) function to execute a function in a background thread. And Ignition provides the system.util.invokeLater(func) function to pass data produced in a background thread back into the EDT so the data can be used to update GUI components.

Here is a simple example:

#This code could be on an actionPerformed event of a button to retrieve, process and display data.
#This code will prevent the GUI from freezing if the code to get and process the data takes awhile.
def async():
    #Fetch and process a lot of data. Return a useful dataset
    dataset = functionThatTakesALongTimeToFinish()	
    def later():
        label = event.source.parent.getComponent("Label")
	label.text = "Processed and retrieved %s results."% dataset.getRowCount()
	event.source.parent.getComponent("Table").data = dataset
    system.util.invokeLater(later)
system.util.invokeAsynchronous(async)

In the code example above the async function is executed in a background thread. The async function takes its time fetching and processing data. During this time the GUI is responsive and not frozen. Then the async function calls the system.util.invokeLater function, passing the function named 'later' as an argument. The system.util.invokeLater executes its argument (the function called later) in the EDT. Notice that function later can access and use the dataset variable that was created in the async function.

It is possible to sprinkle a background thread with multiple calls to system.util.invokeLater in order to update the user interface as the background thread makes progress. This keeps the user informed of the progress of something happening.

Note that the runScript expression function in Ignition executes in the EDT. So runScript should only execute Python code that is fast and not do things that is potentially slow like execute database queries or otherwise access the network.

The PA Power Scripting Module makes writing code that uses system.util.invokeLater and system.util.invokeAsynchronous easier with @run.

Comments

johnjw
https://games.lol/arcade/
6 December 2018

<a href="http://games.lol/arcade/">visit games.lol for arcade games</a>
sadasdasd
www.google.com
25 January 2019

asdasdasdasdsd
Jonathon Coleman
https://www.concretecontractorscincinnati.com
14 February 2019

Thank you so much for this information. I learned a lot about threading system!
$1 web Hosting
https://www.dollaronewebhosting.com/
6 March 2019

This is quite interesting. Thanks for publishing this amazing 8nformative post. I must say keep up posting.
Choies Offers
bhttps://www.promoocodes.com/coupons/choies/
12 March 2019

I really like you efforts which you have put in to write this blog. thanks for shared with us this amazing blog post.
upsers.com login
https://customerservicenumber.mobi/upsers-com-login-guide/
3 April 2019

Je vous remercie de l'information! Je cherchais et ne pouvait pas trouver. Vous me aidé!
Karishma Singh
www.escortsindwarka.com/
9 April 2019

I was waiting for such a long time and I wish for more in future. You did such a great job and I hope you'll share more updates in future.
Meghna Kaur
www.meghnakaur.com/
17 April 2019

http://sillky.in/
http://www.dimpy.in/
http://www.mumbaicallgirlservice.com/
http://www.mumbaiescortscallgirl.com/
http://www.mumbaiescortss.biz
http://www.callgirlinmumbaiescorts.com/
http://www.meghnakaur.com/
http://www.callgirlservicemumbai.com/
https://meghnakaur.blogspot.com/
nehasharma
www.callgirlsinkarolbagh.com
20 April 2019

I am upbeat to be here and this brilliant article. I've found here a great deal of intriguing data for the insight I need. all that you give to us, it was extremely useful and helpful, you rock for sharing this amazing post.
shivani rawat
www.dwarkaescortgirls.com
20 April 2019

I should state I inspired with your work. I wanted to peruse such sort of article which is one of these, I've found here a great deal of fascinating data. this site perfect for the insight I need.
Czarina
https://www.concretecontractorsfortsmith.com
25 April 2019

The main() method is called by the Java virtual machine when the program starts. It instantiates a new Hello frame and causes it to be displayed by calling the setVisible(boolean) method inherited from the Component superclass with the boolean parameter true .
johnmathew
usawriters.org/
12 March 2018

This is a wonderful article. I would like to suggest you that please keep on sharing such type of information with us. I really found it to much informative. It is what i was searching from many days. Well job and thanks for sharing.
Constance C. Cogar
www.topessayservicesau.com/
15 May 2018

This article talks lot about java swings and its using in the development and designing of project. But, it has been good if the author can add little bit of java script and JVM`s that can be very much help to the students like me to understand the steps what you said in this article very easily.
asdasdasd
https://www.google.com
21 July 2018

https://www.google.com
ColdFusion Assignment Help
https://www.coldfusionhelp.net
15 September 2018

Really I Appreciate The Effort You Made To Share The Knowledge. This Is Really A Great Stuff For Sharing. Keep It Up . Thanks For Sharing.
https://www.coldfusionhelp.net
Marketing Research Assignment Help
https://themarketingresearch.com
15 September 2018

Great Info! I Recently Came Across Your Blog And Have Been Reading Along. I Thought I Would Leave My First Comment. I Donít Know What To Say Except That I Have
https://themarketingresearch.com
usps customer service chat
1800liveperson.com/usps/
5 October 2018

Je vous remercie de l'information! Je cherchais et ne pouvait pas trouver. Vous me aidé!
Name: (required)
Email: (required)
Website:
What has four legs, rhymes with bat and says, "Meow?" (One word answer.)
Spam Filter: