Multi-threading - concurrent process execution on a form

86 views
Skip to first unread message

Paul Bowers

unread,
Nov 13, 2023, 3:51:56 AM11/13/23
to Sailforms Users
Screenshot_20231113-081004_Pro.jpgScreenshot_20231113-080937_Pro.jpg

There is a feature of the setFocus command that I encountered from my previous projects that can be very useful. Up to now my projects have used SetFocus to execute code in a linear method on a single thread, and create traditional loops recursions etc. And as such SetFocus was always the last command on any function.

However, I did spot that when SetFocus is not the last command all the following commands continue to execute in addition to the commands on the function I had just called with a SetFocus. In effect multiple functions were executing at the same time.

So how could be be managed in a controlled way. The attached demo builds on the basics from my early programming days when I worked on operating systems.

In the demo there is a field/function I have called for the sake of argument "despatcher" - its sole purpose is to orchestrate the running of the applications - there is a semaphore flag for each application which informs despatcher that an "application" or field function is busy - the last command of the function is to clear this semaphore to despatcher knows it can run it again "SetFocus" on it. The priority field is used to tell despatcher how frequently the function is to run - so they can be slowed in relation to each other.

The applications (functions) themselves should be re-entrant. They dont need to call themselves to loop  as despatcher does that. If the program wants to stop it should not reset the ready to run semaphore and issue a stop. (these are all shown in the demo app).

enjoy playing.

Paul.

Multi_threading_2.sfg
Reply all
Reply to author
Forward
0 new messages