Having multithreading in place can be effective when you have a long and running function in your application.
But what is multithreading?
It allows you to execute more than one function concurrently without making your GUI go unresponsive.
Follow these steps to enable multithreading in your application:
Video version of this tutorial
Set Up #
Select the control and add the event name to it. For example, we have added the ‘TestFunction’ trigger on the onClick event.
Go to the OUTPUT tab and enable the Multithreaded toggle.
Navigate to the LOGIC tab and write your function’s implementation.
Wrap your function in Async, as shown below. (Wrapping the code in async creates a new PowerShell instance and the specified code is executed there)
That’s all. You don’t need to worry about any other aspect as the application will handle it automatically.
Updating the UI using Multithreading #
The data context is available across all threats, so you can update the UI in the same way. For more information, you can refer to the details of Data Context.
(Yes, with POSHGUI, things are this simple! : ))